How can I clone a private GitLab repository?

Solution 1:

It looks like there's not a straightforward solution for HTTPS-based cloning regarding GitLab. Therefore if you want a SSH-based cloning, you should take account these three forthcoming steps:

  • Create properly an SSH key using your email used to sign up. I would use the default filename to key for Windows. Don't forget to introduce a password! (tip: you can skip this step if you already have one ssh key here)

     $ ssh-keygen -t rsa -C "[email protected]" -b 4096
    
     Generating public/private rsa key pair.
     Enter file in which to save the key ($PWD/.ssh/id_rsa): [\n]
     Enter passphrase (empty for no passphrase):[your password]
     Enter same passphrase again: [your password]
     Your identification has been saved in $PWD/.ssh/id_rsa.
     Your public key has been saved in $PWD/.ssh/id_rsa.pub.
    
  • Copy and paste all content from the recently id_rsa.pub generated into Setting>SSH keys>Key from your GitLab profile.

     # Copy to clipboard
     pbcopy < ~/.ssh/id_rsa.pub
    
  • Get locally connected:

     $ ssh -i $PWD/.ssh/id_rsa [email protected]
    
     Enter passphrase for key "$PWD/.ssh/id_rsa": [your password]
     PTY allocation request failed on channel 0
     Welcome to GitLab, you!
     Connection to gitlab.com closed.
    

Finally, clone any private or internal GitLab repository!

$ git clone https://git.metabarcoding.org/obitools/ROBIBarcodes.git

Cloning into 'ROBIBarcodes'...
remote: Counting objects: 69, done.
remote: Compressing objects: 100% (65/65), done.
remote: Total 69 (delta 14), reused 0 (delta 0)
Unpacking objects: 100% (69/69), done.

Solution 2:

You have your ssh clone statement wrong: git clone username [email protected]:root/test.git

That statement would try to clone a repository named username into the location relative to your current path, [email protected]:root/test.git.

You want to leave out username:

git clone [email protected]:root/test.git

Solution 3:

If you're trying this with GitHub, you can do this with your SSH entered:

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

Solution 4:

I tried all of these suggestions. Here's what finally worked for me:

  1. Create an access token at https://gitlab.com/-/profile/personal_access_tokens. NOTE: Be sure to copy the token and save it. You will need it!
  2. git clone https://gitlab.com/USERNAME/REPO.git (replacing USERNAME and REPO with your unique information).
  3. Enter your GitLab user name when requested.
  4. When it asks for your password, enter the access token that you created in step 1. Your GitLab account password will not work for this. The access token is what you want.

Solution 5:

Before doing

git clone https://example.com/root/test.git

make sure that you have added ssh key in your system. Follow this : https://gitlab.com/profile/keys .

Once added run the above command. It will prompt for your gitlab username and password and on authentication, it will be cloned.