How can I clone a private GitLab repository?
GitGithubGitlabGit Problem Overview
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.
Git Solutions
Solution 1 - 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.
Solution 2 - Git
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 - Git
If you're trying this with GitHub, you can do this with your SSH entered:
git clone https://[email protected]/username/repository
Solution 4 - Git
I tried all of these suggestions. Here's what finally worked for me:
- 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!
git clone https://gitlab.com/USERNAME/REPO.git
(replacing USERNAME and REPO with your unique information).- Enter your GitLab user name when requested.
- 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 - Git
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.
Solution 6 - Git
You might need a ~/.ssh/config
:
Host gitlab.YOURDOMAIN.DOMAIN
Port 1111
IdentityFile ~/.ssh/id_rsa
and then you can use git clone git@DOMAINandREPOSITORY
. This means you always use the user git
.
Solution 7 - Git
If you are using Windows,
-
make a folder and open git bash from there
-
in the git bash,
git clone [email protected]:Example/projectName.git
Solution 8 - Git
I created this tool using python with docker for cloning GitLab projects all at once, it will keep the group/subgroup tree structure and will clone/pull all GitLab repos that are not mirrored. It requires docker and docker compose as well as personal access token from your gitlab user along with the group id that will be considered top level group from which you wish to clone.