{"thread":{"id":"47450","subject":"Trying to use insteadOf trick to use different SSH keys for separate github accounts - not working","startedAt":"2017-12-16T07:51:15Z","lastAt":"2017-12-16T10:05:38Z","messageCount":3,"participants":["Asfand Qazi","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"334914","messageId":"CAFTSPUV1E+jCMHzx+rq9Y1agthxcYrzDVY-rThTNCG7BfnPeTg@mail.gmail.com","threadId":"47450","inReplyTo":null,"subject":"Trying to use insteadOf trick to use different SSH keys for separate github accounts - not working","fromName":"Asfand Qazi","fromEmail":"ayqazi@gmail.com","sentAt":"2017-12-16T07:50:02Z","receivedAt":"2017-12-16T07:51:15Z","isPatch":false,"sender":{"key":"ayqazi@gmail.com","avatar":null},"body":"Hello,\n\nHere's what I'm trying to do, that i need your help with to make work:\n\nI have 2 github accounts, each with their own SSH key: my home account\n(default SSH key) and my work account (alternative SSH key). I can\ncreate a virtual hostname in my ~/.ssh/config like so:\n\nHost work.github.com\n     Hostname github.com\n     IdentityFile ~/.ssh/id_rsa-work\n\nand then clone repos with:\n\ngit clone git@work.github.com/MyCompany/la-repo.git\n\nHowever, I'm trying to use Go, which needs to access every repo host\nas 'github.com', and won't support my little SSH hostname trick by\ndefault.\n\nI found out about the 'insteadOf' setting, and thought it would work.\nSo I added this to my global git config:\n\n[url \"git@github.com:MyCompany/\"]\ninsteadOf = git@work.github.com:MyCompany/\n\nand left the SSH hostname setting where it was. Then I tried doing:\n\ngit clone git:github.com/MyCompany/la-repo.git\n\nBut it won't work. With GIT_TRACE=2, I get:\n\n$ GIT_TRACE=2 git clone git@github.com:MyCompany/la-repo.git\n07:46:27.627557 git.c:344               trace: built-in: git 'clone'\n'git@github.com:MyCompany/la-repo.git'\nCloning into 'la-repo'...\n07:46:27.629623 run-command.c:626       trace: run_command: 'ssh'\n'git@github.com' 'git-upload-pack '\\''MyCompany/la-repo.git'\\'''\nERROR: Repository not found.\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.\n\n\nCan anyone help me with this?\n\nThanks\n\nRegards,\n     Asfand\n"},{"id":"334922","messageId":"20171216094840.GA32706@sigill.intra.peff.net","threadId":"47450","inReplyTo":"CAFTSPUV1E+jCMHzx+rq9Y1agthxcYrzDVY-rThTNCG7BfnPeTg@mail.gmail.com","subject":"Re: Trying to use insteadOf trick to use different SSH keys for separate github accounts - not working","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-12-16T09:48:41Z","receivedAt":"2017-12-16T09:54:07Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Dec 16, 2017 at 07:50:02AM +0000, Asfand Qazi wrote:\n\n> I found out about the 'insteadOf' setting, and thought it would work.\n> So I added this to my global git config:\n> \n> [url \"git@github.com:MyCompany/\"]\n> insteadOf = git@work.github.com:MyCompany/\n> \n> and left the SSH hostname setting where it was. Then I tried doing:\n> \n> git clone git:github.com/MyCompany/la-repo.git\n> \n> But it won't work. With GIT_TRACE=2, I get:\n\nIf I'm reading it right, you have the config backwards. You want to\nconvert git@github.com from Go's invocation of Git into your special\n\"work\" alias. So:\n\n  [url \"git@work.github.com:MyCompany/\"]\n  insteadOf = \"git@github.com:MyCompany/\"\n\n-Peff\n"},{"id":"334924","messageId":"CAFTSPUWOhyBamNEJzbSDqZW+GE38+PeW6R+DXnY77yo1dbYQ7Q@mail.gmail.com","threadId":"47450","inReplyTo":"20171216094840.GA32706@sigill.intra.peff.net","subject":"Re: Trying to use insteadOf trick to use different SSH keys for separate github accounts - not working","fromName":"Asfand Qazi","fromEmail":"ayqazi@gmail.com","sentAt":"2017-12-16T10:04:50Z","receivedAt":"2017-12-16T10:05:38Z","isPatch":false,"sender":{"key":"ayqazi@gmail.com","avatar":null},"body":"Thanks it worked! I was reading all the tutorials wrong all this time...\n\nRegards,\n     Asfand\n\n\nOn 16 December 2017 at 09:48, Jeff King <peff@peff.net> wrote:\n> On Sat, Dec 16, 2017 at 07:50:02AM +0000, Asfand Qazi wrote:\n>\n>> I found out about the 'insteadOf' setting, and thought it would work.\n>> So I added this to my global git config:\n>>\n>> [url \"git@github.com:MyCompany/\"]\n>> insteadOf = git@work.github.com:MyCompany/\n>>\n>> and left the SSH hostname setting where it was. Then I tried doing:\n>>\n>> git clone git:github.com/MyCompany/la-repo.git\n>>\n>> But it won't work. With GIT_TRACE=2, I get:\n>\n> If I'm reading it right, you have the config backwards. You want to\n> convert git@github.com from Go's invocation of Git into your special\n> \"work\" alias. So:\n>\n>   [url \"git@work.github.com:MyCompany/\"]\n>   insteadOf = \"git@github.com:MyCompany/\"\n>\n> -Peff\n"}]}