Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to git clone with username and password in gitlab?

I am using gitlab . I want to write a .bat file which contains all the steps so that I can automate all the process , which are as follows:

  1. open cmd.exe /k
  2. git init
  3. git clone https://username:[email protected]/board.git ////// not working
  4. git status

The 3rd point that is git clone https.... is not working in gitBash anymore. I tried using git clone SSH ... and it is working which asked for the passphrase and after logging in it was about to clone the repo. As I want to automate the process by providing the login credentials by-default , how can it be achieved using SSH. Thank you.

like image 361
Blessy Julie Avatar asked Mar 20 '20 17:03

Blessy Julie


People also ask

How do I clone a repository with username and password?

username and password. We can supply the username and password along with the git clone command in the remote repository url itself. The syntax of the git clone command with the http protocol is, git clone http[s]://host. xz[:port]/path/to/repo.

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.


3 Answers

Adding username before gitlab worked for me. It will ask password afterwards.

git clone https://[email protected]/project.git
like image 168
Zhangali Bidaibekov Avatar answered Oct 11 '22 07:10

Zhangali Bidaibekov


While generating keys I did give a passphrase.

Simplest solution would be to generate key without passphrase and use it.

Git clone over https should work but url from your example looks wrong. Go to your project page, choose Clone -> HTTPS url which should look like

https://gitlab.com/<username or groupname>/<projectname>.git

Let's say it is your user's private project and your user would be Julie, then url with credentials would be

https://user:[email protected]/julie/board.git

Test url manually before you start writing your script.

So going to your script example don't init anything just do for https clone:

git clone https://user:[email protected]/julie/board.git
cd board
git status

or if you create ssh key without passphrase and set it on GitLab:

git clone [email protected]:gitlab.com/julie/board.git
cd board
git status
like image 35
makozaki Avatar answered Oct 11 '22 07:10

makozaki


You will need to use access token. Gitlab doesn't allow to use password directly.

git clone https://<username>:<token>@gitlab.com/group/project.git

To create a Gitlab access token:

  1. Click your avatar at the top right corner, select Edit profile
  2. On the left panel, select Access Tokens
  3. Input the Token name and Expiration date (if any)
  4. Check the read_repository checkbox
  5. Click Create personal access token
  6. Remember to save the access token, it appears only once
like image 2
Thach Van Avatar answered Oct 11 '22 08:10

Thach Van