0

I have two users on this machine. user1 is linked to my personal GitHub and user2 is linked to my work GitHub.

Setting the user with this does not work:

git config user.name "User Name"
git config user.email "UserEmail@Host"

If I check which username, user email are it reports user1, which is what I want it to be. BUT when I push it says remote: Permission to user1/repo.git denied to user2.

I'm dying here. There has to be a simple fix for this that I'm just missing.

I remember using SSH for user2 when setting that up. I think that might have something to do with this. I'm happy to delete user2 altogether.

I found this issue, which looks the same, but the fix for it didn't work for me.

Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
iluvramen
  • 15
  • 2
  • What does `git remote -v` say? You chould see the username in the push url. If it's not what you expect, add a new remote or reset the existing remote url or use the full url with the right username instead of `origin`. – ElpieKay Jul 06 '17 at 03:19

2 Answers2

1

user.name is only used to compose your commit message, has nothing to do with authentication, you should config credential.username for network authentication.

You can refer to gitcredentials for more details.

gzh
  • 3,507
  • 2
  • 19
  • 23
0

When you use SSH to connect to GitHub, the values of user.name and user.email are not relevant for authentication. Those are values used by Git when creating commits in the local repository. Pushing/pulling are separate from that.

When you connect to GitHub via SSH, the key that you used to authenticate is how it decides which GitHub user you are. If you want to authenticate as user2, make sure your Git client setup has the SSH key for user2, not the one associated (on GitHub) with user1's account.

Dan Lowe
  • 51,713
  • 20
  • 123
  • 112