Swtiching between different github accounts in mac terminal

less than 1 minute read

I work on multiple projects using github. From time to time I need to switch between different accounts to do github push. I recalled in my first attempt, the following message pop up.

remote: Permission to [github username]/[github repo] denied to ifeng.
fatal: unable to access 'https://[github username]/[github repo]/Myshantou.git/': The requested URL returned error: 403

The logic is…if you are logged onto account A but want to push files into a repo in account B, most likely the error message above will appear.

I have searched and most answers suggested to change “–global user.name”. For examples this one on superuser, this practical guide and another one suggesting to make change an ssh. Stackoverflow also have a number of questios on this, here is one example.

While these might work as proper solutions, I found a quick one that worked for me and just what I needed - Delete Login Info on Keychain!

If you encountered a similar issue, try open your keychain and search for github, then delete the record there.

github switch account delete keychain

After that, when you push again, then terminal should prompt you to enter your login name and password of the account you are pushing to.

github switch account delete keychain - git push

Comments