Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I clone a private GitLab repository?

Tags:

git

github

gitlab

When I do this:

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

I am getting this error:

fatal: HTTP request failed

When I use SSH:

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

I am getting this error:

Initialized empty Git repository in /server/user/[email protected]:root/test.git/.git/
fatal: 'user' does not appear to be a git repository
fatal: The remote end hung up unexpectedly

It's a private repository, and I have added my SSH keys.

like image 317
maximusdooku Avatar asked May 12 '15 22:05

maximusdooku


People also ask

How do I clone a private Git repository with username and password?

If you want to clone it to a specific folder, just insert the folder address at the end like so: git clone https://<token>@github.com/<username>/<repository.git> <folder> , where <folder> is, you guessed it, the folder to clone it to! You can of course use . , .. , ~ , etc.


2 Answers

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. 
like image 92
Ulises Rosas-Puchuri Avatar answered Sep 22 '22 14:09

Ulises Rosas-Puchuri


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 
like image 31
DrCord Avatar answered Sep 24 '22 14:09

DrCord