28

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:password@gitlab.com/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.

Blessy Julie
  • 899
  • 3
  • 8
  • 19
  • What do you mean git clone doesn't work (over https with credentials)? What is the console output? The url you posted as an example looks fishy, maybe you used wrong url? `gitlab.com/board.git` should probably be: `gitlab.com//board.git` – makozaki Mar 25 '20 at 12:34
  • Yeah !!! It is something like as u said ! I want to use SSH to clone and how to give the passphrase with SSH ??? Can u please help me ??? – Blessy Julie Mar 26 '20 at 06:21
  • Why do you need passphrase for ssh clone? You add your public key in GitLab account settings and you use the private counterpart to clone over ssh. – makozaki Mar 26 '20 at 06:27
  • 1
    Yeah !!! when I do git clone then it asks for passphrase . Can u help me how I can insert passphrase in ??? While generating keys I did give a passphrase. – Blessy Julie Mar 26 '20 at 07:11

3 Answers3

19

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

git clone https://user@gitlab.com/project.git
Zhangali Bidaibekov
  • 591
  • 1
  • 7
  • 13
  • Wow, this is really useful. I didn't have to set up my git config afterward. It worked straight away. No public & private tokens were required either. Just had to log in via a pop-up screen that appeared after entering the command on Windows, and done! – Oushima May 04 '22 at 23:52
  • 1
    this worked for me as well :) Such a simple fix. – KoderM May 10 '22 at 16:53
12

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:password@gitlab.com/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:password@gitlab.com/julie/board.git
cd board
git status

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

git clone git@gitlab.com:gitlab.com/julie/board.git
cd board
git status
makozaki
  • 3,772
  • 4
  • 23
  • 47
  • 1
    Thanks for ur reply , I am told to use with ssh key with passphrase. When I tried ``` git clone https://gitlab.com/julie/board.git Cloning into 'board'... remote: HTTP Basic: Access denied fatal: Authentication failed for 'https://gitlab.com/julie/board.git/'``` – Blessy Julie Mar 26 '20 at 16:49
11

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
Thach Van
  • 1,381
  • 16
  • 19
  • Then do we have to enter access token when it asks for password after username while doing `git clone ...` ?? – Abdullah Sep 20 '22 at 06:55
  • 1
    @Abdullah my `git clone` command contains `` and ``. You should add your corresponding username and token into this command. Git will clone your repository successfully without asking for more information. – Thach Van Sep 21 '22 at 05:53