60

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 git@example.com:root/test.git

I am getting this error:

Initialized empty Git repository in /server/user/git@example.com: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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
maximusdooku
  • 5,242
  • 10
  • 54
  • 94
  • You are going to have to give us more info or read the git clone docs and follow them...git clone: http://git-scm.com/docs/git-clone or tell us the actual name of what you trying to clone... – DrCord May 12 '15 at 23:04
  • [This](https://gitlab.com/gitlab-org/gitlab-ce/issues/1937) explained why just copy the link in the project home page is wrong when your project is private. – shellbye Apr 26 '16 at 08:18

9 Answers9

54

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 "your.email@example.com" -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 git@gitlab.com
    
     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.
Iman
  • 17,932
  • 6
  • 80
  • 90
Ulises Rosas-Puchuri
  • 1,900
  • 10
  • 12
  • 2
    This worked for me, expect that I had to clone via ssh instead of https as the final step, changing "https://" to "git@" in the address. – Brett L Aug 03 '20 at 20:10
  • I had to use `ssh -i ~/.ssh/id_ed25519 myusername@git.mysuborga.myorga.com` (or use "$PWD" instead of "~") because I added my public key only to the chosen sub-orga's account at GitLab, *not* to GitLab as a whole. I do not even have a general GitLab user account with the same username. And "ed25519" is the standard of ssh key pair nowadays. And I had to add the output of `ssh-keyscan myusername@git.mysuborga.myorga.com` to `~/.ssh/known_hosts` to suppress the warning `The authenticity of host [xyz] can't be established.` – questionto42 Feb 17 '21 at 14:50
42

You have your ssh clone statement wrong: git clone username git@example.com:root/test.git

That statement would try to clone a repository named username into the location relative to your current path, git@example.com:root/test.git.

You want to leave out username:

git clone git@example.com:root/test.git
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
DrCord
  • 3,917
  • 3
  • 34
  • 47
  • 3
    This was the first thing I tried. It asks password for git@example.com and then denies the password since I am not the admin (I am guessing?) – maximusdooku May 12 '15 at 22:48
  • 2
    Ofcourse. I am only using example.com to obfuscate my identity. – maximusdooku May 12 '15 at 22:53
  • is your username `git`? – DrCord May 12 '15 at 22:56
  • @maximusdooku You probably need to put your private key in the path. – Zahaib Akhtar Aug 12 '17 at 00:46
  • 1
    This answer is for those who use username and password. If you want to use your private SSH key (with the public key being added to your private GitLab project before), see the answer of @UlisesRosas-Puchuri: you would need to `ssh -i` your private key to the private gitlab project so that both know each other before you clone the project. – questionto42 Feb 17 '21 at 14:29
33

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

git clone https://username@github.com/username/repository
garryp
  • 5,508
  • 1
  • 29
  • 41
  • Hi, I am continuing to get this error: fatal: HTTP request failed – maximusdooku May 12 '15 at 22:47
  • Has to be something wrong with the address. The error you are getting is telling you the repo cannot be found, I think your credentials are OK. If possible you could post the exact command you are using (maybe renaming the repo if you don't want to share that). – garryp May 12 '15 at 22:49
  • I have tried both: a) git clone https://serverusername@example.com/serverusername/root/test.git b) git clone https://serverusername@example.com/serverusername/test.git – maximusdooku May 12 '15 at 22:52
  • Put the https prefix in and take out the test.git part. Make sure your repo name is the last part of the address. For example: `git clone https://serverusername@github.com/serverusername/myrepo` – garryp May 12 '15 at 22:56
  • @maximusdooku - if your username is actually `username` then try this `git clone username@example.com:root/test.git` – DrCord May 12 '15 at 23:00
  • Thank you. I tried. Same error as the first comment after getting a message "initialized an empty Git repository...." – maximusdooku May 12 '15 at 23:00
  • Try `git clone git@example.com:username/repo.git` – garryp May 12 '15 at 23:17
  • 6
    the questin is about gitlab – Serge Oct 09 '18 at 20:34
  • When I saw this answer, I thought the question is about gitlab then why you're answering about github. But replacing github with gitlab in your answer is the only thing that worked for me. +1 for that. – Kshitij Bajracharya May 15 '19 at 06:43
  • Downvote. This is an https url, not an ssh url, thus I guess, even as a beginner, that this is *not* "with your SSH entered". See [Clone project at GitLab](https://stackoverflow.com/a/61736911/11154841). – questionto42 Feb 17 '21 at 15:14
  • I just see that I was probably wrong. "with your SSH entered" means the `git@example.com:root/test.git` being put after the https (using GitHub instead, which I do not understand either ;). I cannot take back my downvote, though. – questionto42 Feb 17 '21 at 15:33
7

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.
sjhuskey
  • 71
  • 1
  • 4
  • On this Personal Access Tokens page (where you create them) you can read that "They are the only accepted password when you have Two-Factor Authentication (2FA) enabled." - so perhaps that's why your password didn't work? – Tomeg Mar 12 '22 at 12:07
1

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.

  • 1
    Excellent tip. I used the command `ssh-add id_rsa` after navigating to ~/.ssh then my clone command worked. – insideClaw Jun 10 '20 at 09:13
0

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.

bomben
  • 590
  • 6
  • 16
0

If you are using Windows,

  1. make a folder and open git bash from there

  2. in the git bash,

    git clone git@gitlab.com:Example/projectName.git

0

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.

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 11 '22 at 16:17
0
git clone https://username:password@gitlab.com/example.com:root/test.git

Try this. You will definitely get an answer

  • 1
    Thank you for your interest in contributing to the Stack Overflow community. This question already has quite a few answers—including one that has been extensively validated by the community. Are you certain your approach hasn’t been given previously? **If so, it would be useful to explain how your approach is different, under what circumstances your approach might be preferred, and/or why you think the previous answers aren’t sufficient.** Can you kindly [edit] your answer to offer an explanation? – Jeremy Caney Jul 26 '23 at 00:55
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/34728178) – SavPhill Jul 27 '23 at 16:55