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

 Hi Geeks,

       Hope you are doing well. Recently I was working on one of my projects and I came across a situation, where I'm getting 403 authentication-related errors while pushing my code to one of my public repositories.


       Here are some pointers I would like to highlight the repo is public, so everyone can access it. But still, it is throwing 403 unauthorized exceptions while pushing code to the remote repo.


Below is the step to simulate the above scenario.

Step 1: Created an empty repo on a remote git hub account.

Step 2: Initialise an empty repo locally or clone the above repo on the local machine.

Step 3: Add the above repo as the remote origin to the local git

Step 4: Added local changes to the stage area and try to make a push to the remote repo.


As you can see in step 4 we are getting 403 permission-denied errors.


The solution to the above issue.


Step 1: Create Personal Access Token on GitHub

  •  Log in to your GitHub account
  • Click on the Profile logo in 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, if it is a private one.
 $ 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  





                        Hope you guys find the above information helpful, I as found. Please do comment your queries down below in the comments, see you in my next blog post.

Comments

Popular posts from this blog

Jasper report integration in Spring boot/Spring MVC.

FireBase Crud operation in Spring Boot

Hybris Overview and b2c installation initialization