git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Trying to use insteadOf trick to use different SSH keys for separate github accounts - not working
@ 2017-12-16  7:50 Asfand Qazi
  2017-12-16  9:48 ` Jeff King
  0 siblings, 1 reply; 3+ messages in thread
From: Asfand Qazi @ 2017-12-16  7:50 UTC (permalink / raw)
  To: git

Hello,

Here's what I'm trying to do, that i need your help with to make work:

I have 2 github accounts, each with their own SSH key: my home account
(default SSH key) and my work account (alternative SSH key). I can
create a virtual hostname in my ~/.ssh/config like so:

Host work.github.com
     Hostname github.com
     IdentityFile ~/.ssh/id_rsa-work

and then clone repos with:

git clone git@work.github.com/MyCompany/la-repo.git

However, I'm trying to use Go, which needs to access every repo host
as 'github.com', and won't support my little SSH hostname trick by
default.

I found out about the 'insteadOf' setting, and thought it would work.
So I added this to my global git config:

[url "git@github.com:MyCompany/"]
insteadOf = git@work.github.com:MyCompany/

and left the SSH hostname setting where it was. Then I tried doing:

git clone git:github.com/MyCompany/la-repo.git

But it won't work. With GIT_TRACE=2, I get:

$ GIT_TRACE=2 git clone git@github.com:MyCompany/la-repo.git
07:46:27.627557 git.c:344               trace: built-in: git 'clone'
'git@github.com:MyCompany/la-repo.git'
Cloning into 'la-repo'...
07:46:27.629623 run-command.c:626       trace: run_command: 'ssh'
'git@github.com' 'git-upload-pack '\''MyCompany/la-repo.git'\'''
ERROR: Repository not found.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.


Can anyone help me with this?

Thanks

Regards,
     Asfand

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Trying to use insteadOf trick to use different SSH keys for separate github accounts - not working
  2017-12-16  7:50 Trying to use insteadOf trick to use different SSH keys for separate github accounts - not working Asfand Qazi
@ 2017-12-16  9:48 ` Jeff King
  2017-12-16 10:04   ` Asfand Qazi
  0 siblings, 1 reply; 3+ messages in thread
From: Jeff King @ 2017-12-16  9:48 UTC (permalink / raw)
  To: Asfand Qazi; +Cc: git

On Sat, Dec 16, 2017 at 07:50:02AM +0000, Asfand Qazi wrote:

> I found out about the 'insteadOf' setting, and thought it would work.
> So I added this to my global git config:
> 
> [url "git@github.com:MyCompany/"]
> insteadOf = git@work.github.com:MyCompany/
> 
> and left the SSH hostname setting where it was. Then I tried doing:
> 
> git clone git:github.com/MyCompany/la-repo.git
> 
> But it won't work. With GIT_TRACE=2, I get:

If I'm reading it right, you have the config backwards. You want to
convert git@github.com from Go's invocation of Git into your special
"work" alias. So:

  [url "git@work.github.com:MyCompany/"]
  insteadOf = "git@github.com:MyCompany/"

-Peff

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Trying to use insteadOf trick to use different SSH keys for separate github accounts - not working
  2017-12-16  9:48 ` Jeff King
@ 2017-12-16 10:04   ` Asfand Qazi
  0 siblings, 0 replies; 3+ messages in thread
From: Asfand Qazi @ 2017-12-16 10:04 UTC (permalink / raw)
  To: Jeff King; +Cc: git

Thanks it worked! I was reading all the tutorials wrong all this time...

Regards,
     Asfand


On 16 December 2017 at 09:48, Jeff King <peff@peff.net> wrote:
> On Sat, Dec 16, 2017 at 07:50:02AM +0000, Asfand Qazi wrote:
>
>> I found out about the 'insteadOf' setting, and thought it would work.
>> So I added this to my global git config:
>>
>> [url "git@github.com:MyCompany/"]
>> insteadOf = git@work.github.com:MyCompany/
>>
>> and left the SSH hostname setting where it was. Then I tried doing:
>>
>> git clone git:github.com/MyCompany/la-repo.git
>>
>> But it won't work. With GIT_TRACE=2, I get:
>
> If I'm reading it right, you have the config backwards. You want to
> convert git@github.com from Go's invocation of Git into your special
> "work" alias. So:
>
>   [url "git@work.github.com:MyCompany/"]
>   insteadOf = "git@github.com:MyCompany/"
>
> -Peff

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-12-16 10:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-16  7:50 Trying to use insteadOf trick to use different SSH keys for separate github accounts - not working Asfand Qazi
2017-12-16  9:48 ` Jeff King
2017-12-16 10:04   ` Asfand Qazi

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).