[Solved] Git clone always asks for Personal Access Token (private repo)

Every time I’m trying to clone a private repo I get the prompt to add my username and password.

I looked around to see what’s wrong, because I added my password and didn’t work, and found out that I have to use the Personal Access Token.
Now every time I’m trying to clone a private repo I have to add that (or generate another) token.

Is there a way to clone a private git repo without the token? Or at least to be able to add my password instead of that token?

Enquirer: Anevo

||

Solution #1:

You can use the git credentials storage for storing your username and passwords while accessing the repository over https.
Run

git config credential.helper store

and then

git pull

This will ask your username and passwords and then remember it for future use. Please note running above commands will create a file at ~/.git-credentials and store the credentials in plain text which can be a security risk.
An alternative is to store the credentials in memory rather than the disk. To do this you can run the below command.

git config credential.helper 'cache --timeout=3600'

This way git will not any files on disk and use the memory for storing the credentials. the timeout argument here is used to specify that the credentials should be cached for next 1 hour.

Respondent: Manvendra Singh

Solution #2:

You can clone using SSH, and authenticate using your SSH key. There is a nice guide from GitHub on how to set up git with SSH, and it works very similarly for other providers. After you set it up, don’t forget to clone the repo using the SSH URL (not the HTTPS one), or to change the origin of your cloned repo to the SSH URL.

Respondent: Jan Pokorný

Solution #3:

SOLUTION

This is how I managed to make it work.

Opened a new terminal and add

ssh-keygen -t rsa -b 4096 -C "[github email address]"

The following showed in the terminal

Generating public/private rsa key pair. [press Enter]
Enter file in which to save the key (/home/${USER}/.ssh/id_rsa):
Enter passphrase (empty for no passphrase): [press Enter]
Enter same passphrase again: [press Enter]

Then

cd /.ssh
ls [you should see 3 files]
cat [file].pub

Copy the content then go to your Github profile settings -> SSH and GPG keys -> New SSH key -> paste the content from [file].pub there.
After doing this I can clone the github repo with SSH without the need to add the token.

Respondent: Anevo

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.