How can I store keychain credentials for multiple Github accounts?
Asked Answered
H

1

20

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

Hyatt answered 18/6, 2014 at 0:36 Comment(2)
You can configure this in your global git config file as I outlined here.Apospory
jsdevlife.blogspot.in/2018/02/… May be this will helpfulBuckra
S
19

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.

Shaynashayne answered 18/6, 2014 at 5:51 Comment(1)
Account name in the clone url saved the day.. thank youIaniana

© 2022 - 2024 — McMap. All rights reserved.