'403 Forbidden' error message when pushing to a GitHub repository
Learn how to fix a '403 Forbidden' error message when you push to GitHub using HTTPS.
This article discusses a problem that may occur when you try to push to a remote GitHub repository using HTTPS from a hosting.com server.
Problem
When you try to push changes to a GitHub repository from a hosting.com server using an HTTPS URL, you receive the following error message:
error: The requested URL returned error: 403 Forbidden while accessing https://github.com/github-username/github-repository-name.git/info/refs
Cause
There are a few possible causes for this problem:
-
You typed an incorrect password. Make sure you are using the correct GitHub password for the account.
-
The Git client on the hosting.com server requires a modified HTTPS URL to work correctly. If this is the cause, the password prompt does not even appear when you try to do a push operation.
Resolution
If you are sure you are using the correct GitHub password, there are two ways to resolve the "403 Forbidden" problem:
Method #1: Use SSH
Instead of using HTTPS URLs to push changes to GitHub, you can use SSH instead. For information about how to do this, please visit https://help.github.com/articles/changing-a-remote-s-url.
Method #2: Modify the HTTPS URL
Some hosting.com managed servers have an old version of the Git client installed. To push changes to GitHub using this older client version, you must include your GitHub username in the HTTPS URL.
To do this, follow these steps:
-
Log in to your hosting.com account using SSH.
-
At the command prompt, change to the directory where the Git repository is located.
-
Type the following command:
git config -l | grep url
You should see output that resembles the following:
remote.origin.url=https://github.com/github-username/github-repository-name.git
-
You need to add your GitHub username to the github.com portion of the URL. To do this, type the following command, replacing the github-username and github-repository values with your own account information:
git remote set-url origin "https://[email protected]/github-username/github-repository-name.git"
-
To verify the new remote URL setting, type the following command:
git config -l | grep url
Now when you try to push changes to the GitHub repository, you are prompted for a password, and the push operation should succeed.
Related Articles
Updated 3 days ago