Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I store keychain credentials for multiple Github accounts?

I am running Git on OSX Mavericks and have not had issues until now. What has changed is that I'm trying to use two Github accounts on different repos on the same computer.

The problem is that the osx-keychain is storing the login information from my first account. That was terrific before, but whenever I try to commit or push from my new Github account, it is defaulting to use the keychain's username and password values, and ignoring the locally-defined git config (or even global git config!) files.

I can delete my osx-keychain, and then push to the new account, but in doing so it will create a new keychain for that account, which puts me back at square one: able to push to my secondary account with the new keychain values but locked out of my primary account.

So I'm stuck in an "either-or" situation, and I'm really hoping there's a "both" solution. Any help?

P.S. I have tried this solution, and it did not work, as the osx-keychain appeared to override the SSH Identity functionality

like image 247
Dylan Avatar asked Jun 18 '14 00:06

Dylan


1 Answers

If you are using https url, then the solution you mention wouldn't have any effect: it is for multiple ssh keys.

Regarding https, this question mentions a few solutions, including:

  • By default gitcredentials only considers the domain name.
    If you want git to consider the full path (e.g. if you have multiple GitHub accounts), set the useHttpPath variable to true, as described at gitcredentials.
    Note that changing this setting will ask your credentials again for each URL.

By default, Git does not consider the "path" component of an http URL to be worth matching via external helpers.
This means that a credential stored for https://example.com/foo.git will also be used for https://example.com/bar.git.
If you do want to distinguish these cases, set this option to true.

Also, make sure your https url incudes your account name:

git clone https://[email protected]/auser/aprojectX
git clone https://[email protected]/auser/aprojectY

That will help a credential helper to known which account/password it should be looking for.

Finally, the authentication you are using for accessing a git repo hosting service has nothing to do with:

git config (--global) user.name

That last config is only for setting the author associated with your local commits.
It is not for selecting the account used to access a remote hosting website.

like image 80
VonC Avatar answered Nov 20 '22 11:11

VonC