Wow, thanks. For me it was enough to configure just one rewrite, because my public github account is associated with my default key. Note that I added the missing slash and the username: git config --global \ url.git@gh-org:theorganization/.insteadOf \ git@xxxxxxxxxx:theorganization/ 19.07.2018 19:42, Jeff King пишет: > On Thu, Jul 19, 2018 at 03:24:54PM +0300, Basin Ilya wrote: > >> I have two github accounts, one is for my organization and I want git >> to automatically choose the correct ssh `IdentityFile` based on the >> clone URL: >> >> git@xxxxxxxxxx:other/publicrepo.git >> ~/.ssh/id_rsa >> git@xxxxxxxxxx:theorganization/privaterepo.git >> ~/.ssh/id_rsa.theorganization >> >> Unfortunately, both URLs have same host name, therefore I can't >> configure this in the ssh client config. I could create a host alias >> there, but sometimes somebody else gives me the github URL and I want >> it to work out of the box. > > I think you can hack around this using Git's URL rewriting. > > For example, try this: > > git config --global \ > url.gh-other:other/.insteadOf \ > git@xxxxxxxxxx:other/ > > git config --global \ > url.gh-org:theorganization.insteadOf \ > git@xxxxxxxxxx:theorganization/ > > And then: > > git clone git@xxxxxxxxxx:other/publicrepo.git > > will hit gh-other, which you can configure using an ssh host alias. > > -Peff >