Git Switch is now Git Swap. Due to git releasing a native
switch command, the gem has been renamed.
Git Swap is a command line utility to easily swap between multiple git profiles. It uses a
.gitswap YAML file to configure each profile (name, username, and email) and ssh key.
This gem has been developed for, and only tested on, Mac OS.
Additionally, it requires git version 2.10+. Run
git --version to check your currently install version. If you are using homebrew, you can install a newer version of git with
brew upgrade git.
This gem is not intended to be installed via a Gemfile. Instead, install it yourself:
$ gem install git_swap
If you use rvm, you can save yourself from some headaches by installing git_swap for all gemsets.
$ rvm @global do gem install git_swap
If transitioning from
git_switch, version 0.5.0 or earlier, to
git_swap version 1.0.0 or later, run this command to preserve your current configuration.
cp ~/.gitswitch ~/.gitswap && rm ~/.gitswitch
To run the guided setup, use
git swap --config.
You may also manually create or edit your configuration at
~/.gitswap. The config file is in YAML format. Here is an example.
personal: username: johnnyfive email: email@example.com name: Johnny Smith ssh: ~/.ssh/id_rsa work: username: johnsmith email: firstname.lastname@example.org name: John Smith ssh: ~/.ssh/defmethod_rsa
Note that the ssh key must already exist. See these instructions to generate a new SSH key.
The root keys can be any nickname you want. It should be memorable to make it easy to swap between profiles.
Git Swap follows the convention to create a custom git command. It can be invoked as follows, to either set your git profile locally (no flag) or globally (
$ git swap personal $ git swap personal -g
Note that in previous versions, invoking
git swap would remove all identities from
ssh-add, except the one specified. You can always readd them using
Newer versions use git config to specify which ssh identity to use when running git commands.
--listto list configured profiles
git swap -l
--verboseto print more detailed output
git swap personal -v
The gem is available as open source under the terms of the MIT License.