Question

I've setup a second git identity to use with my company account, by creating a second ssh key and adding a config file to the ~/.ssh directory, as explained in this blog post:

I have also set the new user name and email of the local repository:

$(path to repo directory) git config user.name "<Company account user name>"
$(path to repo directory) git config user.email "<Company account user email>"

as suggested in one of the comments in that blog post.

I've created a local repository, and one on Github (company account). I've added the (public) repo on GitHub as a remote (origin) of the local one.

I can pull from the remote, (using either the command line and SourceTree), but when I try to push, I get this error:

ERROR: Permission to <company user name>/Test.git denied to <personal user name>.
fatal: Could not read from remote repository.

That is, git is trying to push using my existing, personal account, NOT the new, work one.

How can I have git push using the proper account's credentials?

Was it helpful?

Solution

I think it was the whole osx keychain/keychain helper thingy that might be to blame.

Here is how I solved it:

1) Delete local repo ("start from scratch").

2) Clone again from origin (GitHub).

3) Check that repo is configured to use new account's e-mail address (it was).

4) Check again hosts in .ssh/config file, make sure each is set up with the proper key (they were).

5) Out of desperation, assign the new rsa key to BOTH accounts/hosts in said .ssh/config file. still can't push, and still being addressed by old account's e-mail address (something's being cached somewhere...), hence can't authenticate.

6) Launch KeyChain Access.app, search for "git", "GitHub" and delete all "internet password" entries. <- THIS DID THE TRICK

After deleting everything, I had to re-enter my credentials for both accounts when prompted (SourceTree), but now I have two (working) repositories using two different GitHub accounts, side by side on the same machine.

Hope this helps someone.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top