The problem
When you run git push over HTTPS, Git stops with this message:
error: The requested URL returned error: 403 Forbidden while accessing https://github.com/github-username/github-repository-name.git/info/refs
The cause
Most of the time the password is wrong, or Git does not know which GitHub user you are. Check that you are using the right account first. Note that GitHub no longer accepts your account password for Git. Use a personal access token in its place.
Fix 1: Use SSH instead of HTTPS
Change the remote address of your repository to an SSH address. GitHub explains how in its guide "Changing a remote's URL". After that, Git uses your SSH key and does not ask for a password.
Fix 2: Add your user name to the HTTPS address
- Open a terminal and go to the folder of your repository.
- Show the current remote address:
git config -l | grep url
You should see a line like this:
remote.origin.url=https://github.com/github-username/github-repository-name.git
- Put your GitHub user name in front of
github.com. Replace the values with your own:
git remote set-url origin "https://github-username@github.com/github-username/github-repository-name.git"
- Check the new address:
git config -l | grep url
- Run
git pushagain. Git asks for a password. Paste your personal access token. The push should now work.
Tip: Never put your token inside the remote address. Git would save it in plain text in the repository config.
Quick recap
- A 403 on push means GitHub refused your login.
- Use a personal access token, not your account password.
- Switch to SSH, or add your user name to the HTTPS address.