Reputation: 11
I saw the suggestion to work with multiple Github accounts is to create a SSH config with multiple entries like so:
Host aliasUser1
HostName github.com
User git
IdentityFile ~/.ssh/user1
Host aliasUser2
HostName github.com
User git
IdentityFile ~/.ssh/user2
This will allow me to run commands like so:
git clone aliasUser1:user1/repo.git
git clone aliasUser2:user2/repo.git
But I prefer to have a configuration that will allow me to run the commands as usual and make the differentiation based on the org/ user name, meaning: git clone [email protected]:user1/repo.git -> will use user1 key git clone [email protected]:user2/repo.git -> will use user2 key
is this configuration possible?
I'm not sure what to try currently
Upvotes: 1
Views: 107
Reputation: 60565
Yes, you can do this, you have to do a little finagling. Git's got a general-enough url rewriting config, url.<realprefix>.insteadof
.
git config url.workme:user1/.insteadof [email protected]:user1/
and from then on Git will rewrite the [email protected]:user1/
prefix to workme:user1/
and then recognize the result as (still) using ssh; you need to configure your ssh to put the real connection data back:
host workme
hostname github.com
user git
identityfile ~/.ssh/user1.pub
Upvotes: 1