It happens often that we are working on couple of repositories, performing push/pull operations on our branches. I faced one issue quite pre-dominantly that when I am trying to push into repository that required my different username, hosted on a different Github account of mine, then I saw that Git is using my previous username and the push is failing because of incorrect username.
git config --global user.name 'anshulbravo'
I tried to set the global username again with the valid one, but that didn’t work. Git still kept on trying to push with the incorrect username for the repository.
What worked for me was following:
git config --local credential.helper ""
git push origin master
Doing this made Git ask me for username everytime I am trying to push. This helped, and helped like a soothing breeze. Now I was able to provide the correct username and provide the password for it, and the push went successful.