'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.



Solution 1:[1]

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

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

Solution 2:[2]

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

Solution 3:[3]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Zhangali Bidaibekov
Solution 2 makozaki
Solution 3 Thach Van