Shane Bartholomeusz

Geek and lover of all things tech related

How To: Clone GIT Repo Using Personal Access Token

Overview

In this post I’ll show you how you can clone a Git repository using a Personal Access Token instead of a regular password.

Personal Access Tokens are useful in a variety of situations. I recently opted to use an access token on a work laptop rather than using my ‘god mode’ credentials. That way, if I needed to hand the laptop back to my employer I could easily revoke the access.

Enough talk … lets get to it!

GitHub Icon

Create a Token

First thing we need to do is create a Personal Access Token through the Github online portal.

1. Log into you GitHub account

2. Click your profile picture in the right hand menu and then navigate to SETTINGS > DEVELOPER SETTINGS within GitHub (or click this link to go straight there).

GitHub Settings Screenshot

3. Click ‘Generate New Token’ to create a new token.

Name the token appropriately so you can identify it later on (if needed) and select the appropriate scope. I’d suggest you select the Repo – Full Control scope.

IMPORTANT: Make note of the token because once you close the window you won’t be able to view the token again!

4. Name the token appropriately so you can identify it later on (if needed) and finally, select the appropriate scope. Note: At a minimum for cloning a repo I suggest you select the Repo – Full Control scope.

GitHub Settings Screenshot
GitHub Create New Personal Access Token

Clone Repo With Your Token

Now lets clone a repo using your newly generated Personal Access Token. You’ll notice that I’m using the token instead of the ordinary account password.


$ git clone https://github.com/fakeuser/fake-repo.git
Username: <your_username>
Password: <your_personal_access_token>

Common Issues

While Cloning a Private Repo using a Personal Access Token I encountered the below error:

ERROR: Repository not found.

The cause of the issue is lack of privileges. Make sure you have granted ‘full control’ access rights to your Personal Access Token, anything less did not work for me.

GitHub Settings Screenshot

Final Thoughts

I hope you’ve found this post useful. If you have any other tips to share, please post them below to help others out there.

Shane Bartholomeusz

4 Comments

  1. I am unable to find a way to pass the personal access token while cloning the private repository. While cloning, I am not getting option to enter my username or password. I have even tried to provide the usename:password@github.com format in the HTTPs URL while cloning the repository. FYI, my token is a successfully created and authenticated with the private repository.

    • Shane Bartholomeusz

      26th July 2021 at 9:32 pm

      I suspect the credentials have been cached on your local machine, so you’ll need to clear the cache. You should then be prompted for the credentials once again. If you are using Windows then the credentials will be stored in the Windows Credential Manager by default.

  2. using the following format worked for me: git clone https://@github.com//

Leave a Reply

© 2024 Shane Bartholomeusz

Theme by Anders NorenUp ↑