I have several repos on github, and two different accounts. My accounts are the creators of both repos which are discussed below (username1 created repo1 and username2 created repo2).
How do I configure tortoisegit to set which credentials (putty key) to use when connecting to each github repo?
On Tortoisegit > settings > Git > Remote, I have repo1 configured as:
Remote: origin
URL: [email protected]:username1/MyRepo1.git
Push URL: (blank)
Putty Key: path/to/account1.ppk
And repo1 configured as:
Remote: origin
URL: https://github.com/username2/myRepo2.git
Push URL: (blank)
Putty Key: path/to/account2.ppk
However, when I try to push to the first repo, I get the error:
git.exe push --progress "origin" master:master
ERROR: Permission to username1/MyRepo1.git denied to username2. <-- why is username2 showing up here?!?
fatal: Could not read from remote repository.
... why is it trying to use username2 (which is not configured anywhere on repo1) to connect? And where can I configure which username to use when connecting?
I tried changing the settings in Tortoisegit > settings > Git, to set Name: username1
and Email: [email protected]
but it didn't make any difference (got the same error message when trying to push).
I've tried to follow the explanations on the accepted answer of TortoiseGit - Multiple GitHub repositories with different key pairs each , however, I cannot work out what to do for any of them...
Well... the instructions on both links are too general to be useful. There's no concrete example to work with.
It basically says "change to 'ssh'... but that just creates new problems. How do I configure OpenSSH to make the connection? Or tell it which credentials to use for which repo? Again... no concrete examples.
If I change the connection for repo1 to https://github.com/username1/MyRepo1.git
then I get the error fatal: unable to access 'https://github.com/username1/MyRepo1.git/': The requested URL returned error: 403
So I changed it to https://[email protected]/username1/MyRepo1.git
and then I got a pop-up asking me to log into github. I did that as a last resort and it (seems to have) worked, however, I want to use the ssh keys, not login based auth.
So... back to the question: how do I configure TortoiseGit to use different SSH credentials to connect to different repos?
And, for bonus points... can I configure a default set of credentials for TortoiseGit to use and then just over-ride those on a repo-by-repo basis when something different is needed? If so, how? (I ask because this seems to be what is happening unintentionally, so I wonder if there's a way to intentionally use it as a feature!)
Thank you for reading, and thanks in advance for helping!
how do I configure TortoiseGit to use different SSH credentials to connect to different repos?
First, use SSH URLS for both repositories.
Since repo2
is configured with https://github.com/username2/myRepo2.git
, the SSH key is simply ignored.
And that is why Tortoise mentioned username2
You need [email protected]:username2/myRepo2.git
if you want your associated SSH key to be used at all.