A simple tool to handle multiple git accounts, using multiple SSH keys.
I ran into the problem when having to collaborate on 2 distincts github
accounts simultaneously: my own account and the one I was running for my organization.
Here is the pitfall: each SSH key can be associated with one and only one account.
Unfortunately, git
automatically takes the default key (typically $HOME/.ssh/id_rsa
) for granted.
So creating a fresh new SSH key (let's say $HOME/.ssh/id_rsa2
) and adding the corresponding public key to the repository was not enough to solve the problem.
Indeed, what git
lacks is an option (like --identity
on ssh
command) to specify which private key should be used.
And here comes su-git!
First, clone the project into a temporary directory:
$ cd /tmp
$ git clone https://github.com/yannoff/su-git.git
Then, go inside su-git
directory,
$ cd su-git
then run:
$ make
$ sudo make install
Now su-git
can be called from anywhere on your system.
Prior to the first run of su-git
, you need to configure which identity file will be used for the current dir:
$ git config ssh.identity /path/to/your/private_key
NOTE:
su-git
leverages the powerfulgit-config
engine to store itsssh.identity
option. This means you can configure a global setting for your private key, and override it on a per-project level, as you would do for any other regular git configuration value.
Now you can use su-git
for push
/pull
operations, exactly the same way as git
, having your identity handled automatically.
Example:
- Use
su-git
for cloning
$ su-git clone --identity ~/.ssh/your_rsa [email protected]:dummy/my-project.git
NOTE: When cloning, there is no
.git
folder in the current directory, sogit config
cannot be used here, even if a global setting exists forssh.identity
.
- Configure your identity file from inside the working dir
$ cd my-project
$ git config ssh.identity ~/.ssh/your_rsa
- Work locally using
git
$ git checkout -b feature/my-awesome-feature
...
$ git add .
$ git commit -m "My commit"
...
- Use
su-git
when pushing your local branch
$ su-git push -u origin feature/my-awesome-feature
This project was proudly pushed using su-git.
Licensed under the MIT License.