[Solved] fatal: unable to access 'https://github.com/username/location.git/': The requested URL returned error: 403

Article Sharif Ahmed

While working with Github you may face that, Git is saying 403 when trying to perform the git push origin master command. This fatal error occurs because password authentication for accessing Github's private repository has been disabled. The error looks like,

fatal: unable to access 'https://github.com/username/location.git/': The requested URL returned error: 403

If you are struggling with the error here is a quick solution for you.

Step 1: Create Personal Access Token on Github

  • Log in to your GitHub account
  • Click on the Profile logo on the top right corner
  • Click on Settings
  • Then, Click on Developer settings for the left sidebar
  • Next, Click on Personal access tokens for the left sidebar
  • After that, Click on Generate new token
  • Give your token a descriptive name on the Note field
  • Select Expiration time and preferred scopes
  • Click on Generate token
  • Finally, you can copy that token and use it to authenticate. You can use the token instead of a password for Git over HTTPS or can use it to authenticate to the API over Basic Authentication.


Step 2: Use Personal Access Token for Authentication

Using HTTPS URL

Personal access tokens can only be used for HTTPS Git operations. Once you have a token, you can enter it instead of your password when performing Git operations over HTTPS. For the existing remote repository, you need to update the remote URL by using,

$ git remote set-url origin https://[githubtoken]@github.com/[username]/[repositoryname].git
$ git push origin master

Or, while cloning any repository,

$ git clone https://github.com/username/repo.git
Username: Enter your username
Password: Enter your access token
Using SSH

For performing Git operation you just need to change the URL. First, make sure your SSH keys are correctly set up. Then, To update the URL you have to run

$ git remote set-url origin git@github.com:[username]/[repositoryname].git
$ git push origin master

Thank you for reading the article. Hope following the steps properly will solve your problem.

But if still, you are facing a problem to generate or use your Personal Access Token and perform Git Operations you can read this article with details step by step process.