33

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.

4
  • 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/<user or group name>/board.git Commented Mar 25, 2020 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 ??? Commented Mar 26, 2020 at 6: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. Commented Mar 26, 2020 at 6:27
  • 1
    Yeah !!! when I do git clone <SSH> then it asks for passphrase . Can u help me how I can insert passphrase in ??? While generating keys I did give a passphrase. Commented Mar 26, 2020 at 7:11

3 Answers 3

29

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

git clone https://[email protected]/project.git
Sign up to request clarification or add additional context in comments.

2 Comments

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!
this worked for me as well :) Such a simple fix.
18

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

4 Comments

Then do we have to enter access token when it asks for password after username while doing git clone ... ??
@Abdullah my git clone command contains <username> and <token>. You should add your corresponding username and token into this command. Git will clone your repository successfully without asking for more information.
Unfortunately, it doesn't work for private repository.
I have just tested with HTTP login instead of token and it seems to work, so long you do not have @ or : in your password. Be careful though that means your password will be stored in clear in your clone .git directory.
13

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

2 Comments

Thanks for ur reply , I am told to use with ssh key with passphrase. When I tried ``` git clone gitlab.com/julie/board.git Cloning into 'board'... remote: HTTP Basic: Access denied fatal: Authentication failed for 'gitlab.com/julie/board.git'```
It was told passing a git password is not allowed anymore. Git token might be a solution, but in case of private GitLab it doesn't work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.