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.
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.