Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Fix the "403 Forbidden" Error When You Push to GitHub

Git says the push failed with a 403 error. Here is why it happens and two ways to fix it.

How-To Guides2 min read5 steps

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

  1. Open a terminal and go to the folder of your repository.
  2. 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
  1. 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"
  1. Check the new address:
git config -l | grep url
  1. Run git push again. 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.