Fixing GitHub 403 errors during push caused by wrong credentials
Posted: (EET/GMT+2)
GitHub is a very common repository to store your source code in, and many of use it for both work and personal stuff. Business and pleasure, as the saying goes.
Now, if you get a HTTP 403 error when pushing your code to GitHub, one common reason is that Git is using the wrong credentials.
This can happen if you have multiple accounts configured (work, personal, per-project). Git may pick up cached credentials from a previous repository and try to use those for the new one.
A quick way to check which username Git is using is the run:
git config credential.username
If the value is either empty, or not what you expect, you can override it for the current repository:
git config credential.username your-username
After that, try the push again. In many cases, Git will now prompt for credentials using the correct username, or use the updated configuration together with your credential manager.
If the problem persists, you may also need to clear cached credentials. On Windows, this is usually handled by the Git Credential Manager. So, you can run:
git credential-manager erase
Then retry the operation so that Git will ask for credentials again.
So the practical takeaway is simple: if you see a 403 and you have multiple GitHub accounts, check which username Git is using before looking for other issues.
Happy versioning!