GitHub changing user account on windowsPosted: 18/06/2016
I’m a beginner slowly learning how to use git and right away during my learning process I encountered a big thorn in my foot. The following article applies to git on windows.
Search for git push 403 and you’ll get a grip of this problem.
The problem for me was swapping between different github user accounts but no reinstall or changing of user credentials would do it for me. Changing the local account did not work:
git config user.name MyNewUsername git config user.email MyNewEmail
Neither did changing the global account:
git config --global user.name MyNewUsername git config --global user.email MyNewEmail
Not even adding username and password directly into the push URL worked:
git push https://username:firstname.lastname@example.org/yourname/yourrepo.git
It would still attempt to push using my old account username…
The request URL returned error: 403
The next thing I tried that almost worked. However it would require me to re-enter login credentials every single time I was pushing files to the repository. What I did was delete the SSH settings stored in a file named known_hosts located in the path %userprofile%\.ssh
This is not a good workaround as re-entering both username and password every time you push can be a bit tedious.
I don’t know if I’m missing some kind of setting or if git is just ignoring to check the proper account name associated with stored SSH key. Is it just attempting to use the most recent and giving up? Shouldn’t it check and use the proper key if there are multiple?
If it’s not a setting (which I can’t find for the life of me) this is probably a bug in the windows release.
The best solution ?
The following was the solution that finally worked satisfactory for me: http://stackoverflow.com/questions/15381198/remove-credentials-from-git
This command changes so that git uses windows own credential manager:
git config --global credential.helper wincred
After this setting is changed try pushing once again, if it fails then remove the entries related to github in the windows Credential Manger in the Control Panel. See the screenshot image below.
The next time you push it should now prompt you for login credentials AND REMEMBER THEM! phew
It never occurred to me that git could use windows own credential manager in the windows control panel.
The only minor annoyance remaining is that you still have to delete your old credentials every time that you wish to use another github account.
Please leave a comment and/or correct me if I got something wrong or if you want to add additional information.