As you authenticate with your ssh
-keys, you should use a different ssh
-key for each account.
You then need to configure the ssh
-key used for pushing changes, which then again determines the account to authenticate against github
.
You can do this, by setting a different core.sshCommand
for each local repository.
The following example assumes repo1
is using ~/.ssh/key1
and repo2
is using ~/.ssh/key2
.
In repo1
, you set core.sshCommand
to use ~/.ssh/key1
like this.
git config --local core.sshCommand "ssh -i ~/.ssh/key1"
In repo2
, you set core.sshCommand
to use ~/.ssh/key2
like this.
git config --local core.sshCommand "ssh -i ~/.ssh/key2"
To configure core.sshCommand
while cloning a repository, use the following command
git clone -c core.sshCommand="ssh -i ~/.ssh/key1" git@github.com:repo1/repo1.git
Note that this must be done for every local copy of the github
-Repository, and also may not working if not using a Unix
operating system or the git bash for windows
.
Also see this answer