/ troubleshooting

git Permission to userA/x denied to userB

This might be an uncommon issue and hard to debug.


on Mac, when git push -u origin master to a remote repo through https, you might encounter this err:

remote: Permission to userA/x.git denied to userB

And you've set the [user] of global/system/local config to userA;
And the only ssh pubkey has been added to userA;
And the host github.com in ~/.ssh/config is configed to the only ssh pubkey;
But git still trying to use userB...

WTF, what happened?

(I even tried fs_usage to monitor all file opened by git, and grep -r userB / 2>/dev/null, but still no clue..)

(Furthermore, u can git push through ssh but not by https.)

Root Cause

Lei sent me a link talking about a similar issue on win and I finally figured it out:

There's a credential in keychain:
That's why git always uses userB when interacting with https://github.com by default.

BTW, [user/email] in git global/system/local config doesn't indicate the login credential, so it doesn't help by changing them.


  • Open Keychain Access
  • Search 'github.com'
  • Delete the credential

Then git will ask about the username when you push.
So, back to use ssh again, lol
If you want https to store your credential, then you need to new a keychain access, and that's why I added it before (I guess).

git Permission to userA/x denied to userB
Share this