Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clone a private repo of github with username and password

I have configured Account A on my system with Global configurations and I can clone all my repos from there.

Now I don't want to change the configuration and I want to clone and do all operations of account B with my username and password. How can I do this?

I have tried:

git clone username:[email protected]:*****/******.git 

But with no success.

like image 921
Usman Afzal Avatar asked Mar 31 '14 06:03

Usman Afzal


People also ask

How do I clone a private git repository with username and password?

If you want to clone it to a specific folder, just insert the folder address at the end like so: git clone https://<token>@github.com/<username>/<repository.git> <folder> , where <folder> is, you guessed it, the folder to clone it to! You can of course use . , .. , ~ , etc.

Can I clone a private GitHub repository?

You also have the option to clone a private GitHub repository using SSH. To do this, you need to start by generating an SSH keypair on your local device. Then add a public key to your GitHub account.


1 Answers

You can try with the complete https url:

git clone https://username:<token>@github.com/*****/******.git 

If you omit the https:// part (and use ':' instead of '/'), it would be interpreted like an ssh url.

The GitHub help page "Which remote URL should I use?" confirms an https url can access private repos.

Note: I wouldn't put the token directly in the url, but use a credential manager to get the right password for the right user.

git clone https://[email protected]/*****/******.git 

Reminder: since Aug. 2021 Token (or SSH key) authentication are required for all authenticated Git operations for GitHub.
Here, the token is a PAT (Personal Access Token).

like image 96
VonC Avatar answered Oct 02 '22 22:10

VonC