How can I clone a private GitLab repository?

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

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.

Tags:

Git

Github

Gitlab