Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git clone with different username/account

Tags:

git

clone

How can I clone something on git with a different account?

For example, I might have been using one account for cloning, and now I need to access a repo that only a different account has access to.

Thanks for the help

like image 643
David Callanan Avatar asked Sep 22 '16 16:09

David Callanan


People also ask

How do I clone a git repository from another user?

In order to clone a git repository into a specific folder, execute the “git clone” command and specify the destination folder at the end. $ git clone https://github.com/username/project.git myproject Cloning into 'myproject'... remote: Enumerating objects: 813, done.

How do I clone a git repository with username?

Clone the Repo 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.

How do I clone a git repository without username and password?

One way to clone a repository without having to enter your password would be to create an app-password and use it while cloning. That done, git won't prompt for user name and password. Mind that this is a URL and needs to be encoded as an URL then. This will leave the password in the git configuration.


2 Answers

If you clone via https you can do something like

git clone https://[email protected]/username/repository.git 

This will prompt you for a password.

You can also directly provide a password by calling

git clone https://username:[email protected]/username/repository.git 

But be aware that the password will be saved in .git/config and your bash history in that case which is not safe. If you don't like to enter the password every time you should consider cloning via ssh.

like image 131
DirkH Avatar answered Oct 04 '22 16:10

DirkH


I tried above solution but it seems that support for password authentication was removed on August 13, 2021.

The solution is to use a personal access token which you can generate in Settings -> Developer Settings -> Personal access tokens.

After that:

git clone https://username:[email protected]/username/repository.git 
like image 34
Juani D'Ambrosio Avatar answered Oct 04 '22 15:10

Juani D'Ambrosio