94

I'm trying to do a simple git clone https://github.com/org/project.git on a CentOS box but get:

error: The requested URL returned error: 401 while accessing https://github.com/org/project.git/info/refs

fatal: HTTP request failed

It never prompts me for my username/password, just fails.

I can make the exact same call on my Mac no problem- what am I missing?

Yarin
  • 173,523
  • 149
  • 402
  • 512
  • Its a fresh wide open CentOS 6.3 box on the cloud- internet access not a problem – Yarin Sep 21 '12 at 21:14
  • @Yarin: I trust you already read this : https://help.github.com/articles/https-cloning-errors The last resort would be to use ssh I think. Also, you might want to check the email your git is configured with... not sure if it helps but make sure it corresponds to the one you use with your github account. – greg0ire Sep 21 '12 at 21:18
  • yeah- none of those check out- literally copying a working command from my mac terminal into the linux terminal- no password prompt, just craps out – Yarin Sep 21 '12 at 21:21

9 Answers9

219

The answer was simple but not obvious:

Instead of:

git clone https://github.com/org/project.git

do:

git clone https://username@github.com/org/project.git

or (insecure)

git clone https://username:password@github.com/org/project.git

(Note that in the later case, your password will may be visible by other users on your machine by running ps u -u $you and will appear cleartext in your shell's history by default)

All 3 ways work on my Mac, but only the last 2 worked on the remote Linux box. (Thinking back on this, it's probably because I had a global git username set up on my Mac, whereas on the remote box I did not? That might have been the case, but the lack of prompt for a username tripped me up... )

Haven't seen this documented anywhere, so here it is.

Matthieu Moy
  • 15,151
  • 5
  • 38
  • 65
Yarin
  • 173,523
  • 149
  • 402
  • 512
  • 4
    Thank you for mentioning the `git config --global user.name` detail, that was it for me! – GermanK Oct 30 '13 at 18:02
  • Note that as of git 1.7.10 you *will* be prompted for a username, [according to @JERC](http://stackoverflow.com/a/20646216/165673), so this should no longer be an issue.. – Yarin Dec 20 '13 at 23:40
  • I had the same issue (with GIT 1.7.1, CentOS5), but I couldn't add the username/pwd into the URL-s becouse I had to install bundles from private Bitbucket repos (and obviously I won't add username and pw info into a composer.json/composer.lock). Becouse GIT didn't allow me to type them manually, I had to go the hard way, and updated GIT with the help of the RPM Forge Repository (http://guru4hp.blogspot.hu/2012/08/how-to-configure-rpmforge-repository-on.html). I followed @muness' guide found here: http://serverfault.com/questions/448814/yum-doesnt-install-latest-version-of-git-on-centos6 – hattila Jul 28 '14 at 14:35
  • 2
    This is the answer if you are using git 1.7.1 on linux – Louie Miranda Jul 30 '14 at 05:20
  • 1
    applicable if using anything prior to 1.7.10 – Amit G Aug 06 '14 at 12:47
  • I guess I didn't realize that "org" should be replaced by my oranization name. I really am a n00b. Once I did that, and of course put in my actual "username", I was prompted for my password and now I am rolling. By the way, I just installed git on CentOS and 1.7.1 is what they handed me. – Buttle Butkus Nov 11 '15 at 22:50
34

You can manual disable ssl verfiy, and try again. :)

git config --global http.sslverify false
Chu-Siang Lai
  • 2,658
  • 1
  • 24
  • 21
  • 3
    For the BeagleBone Black with Angstrom, opkg doesn't supply the required version to do ssl verification so this is the only choice I've found to work. – Josiah Feb 09 '14 at 21:16
  • 1
    @flickerfly statement is valid..no other way to clone using https except using this method when using beaglebone black with Angstrom OS. – Funky81 May 31 '14 at 00:33
  • 1
    Works on Centos. Thank you. – 030 Jun 03 '14 at 17:52
  • 1
    Disabling ssl verification is a bit dangerous. A malicious man-in-the-middle could theoretically send you a modified git repo. – Mark Doliner Sep 29 '14 at 18:51
  • Also had to do this when using GitLab – Gerard Aug 23 '16 at 11:54
13

I met the same problem, the error message and OS info are as follows

OS info:

CentOS release 6.5 (Final)

Linux 192-168-30-213 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

error info:

Initialized empty Git repository in /home/techops/pyenv/.git/ Password: error: while accessing https://waterdrops@github.com/pyenv/pyenv.git/info/refs

fatal: HTTP request failed

git & curl version info

git info :git version 1.7.1

curl 7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2 Protocols: tftp ftp telnet dict ldap ldaps http file https ftps scp sftp Features: GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz

debugging

$ curl --verbose https://github.com

  • About to connect() to github.com port 443 (#0)
  • Trying 13.229.188.59... connected
  • Connected to github.com (13.229.188.59) port 443 (#0)
  • Initializing NSS with certpath: sql:/etc/pki/nssdb
  • CAfile: /etc/pki/tls/certs/ca-bundle.crt CApath: none
  • NSS error -12190
  • Error in TLS handshake, trying SSLv3... GET / HTTP/1.1 User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2 Host: github.com Accept: /

  • Connection died, retrying a fresh connect

  • Closing connection #0
  • Issue another request to this URL: 'https://github.com'
  • About to connect() to github.com port 443 (#0)
  • Trying 13.229.188.59... connected
  • Connected to github.com (13.229.188.59) port 443 (#0)
  • TLS disabled due to previous handshake failure
  • CAfile: /etc/pki/tls/certs/ca-bundle.crt CApath: none
  • NSS error -12286
  • Closing connection #0
  • SSL connect error curl: (35) SSL connect error

after upgrading curl , libcurl and nss , git clone works fine again, so here it is. the update command is as follows

sudo yum update -y nss curl libcurl

Warrren Liu
  • 131
  • 1
  • 2
12

Make sure you have git 1.7.10 or later, it now prompts for user/password correctly. (You can download the latest version here)

Yarin
  • 173,523
  • 149
  • 402
  • 512
JERC
  • 1,584
  • 3
  • 17
  • 38
  • 4
    I had the same problem, My git Version was 1.7.1 when I upgrade to 1.7.10 now It prompts User/Password Correctly!!, (the version 1.7.1 IS NOT THE SAME TO 1.7.10) Please check the versions before to devoted. – JERC Dec 19 '13 at 22:15
10

I had to specify user name to work on 1.7.1 git version:

git remote set-url origin https://username@github.com/org/project.git
Andrius
  • 101
  • 1
  • 2
6

As JERC said, make sure you have an updated version of git. If you are only using the default settings, when you try to install git you will get version 1.7.1. Other than manually downloading and installing the latest version of get, you can also accomplish this by adding a new repository to yum.

From tecadmin.net:

Download and install the rpmforge repository:

# use this for 64-bit
rpm -i 'http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm'
# use this for 32-bit
rpm -i 'http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.i686.rpm'

# then run this in either case
rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt

Then you need to enable the rpmforge-extras. Edit /etc/yum.repos.d/rpmforge.repo and change enabled = 0 to enabled = 1 under [rpmforge-extras]. The file looks like this:

### Name: RPMforge RPM Repository for RHEL 6 - dag
### URL: http://rpmforge.net/
[rpmforge]
name = RHEL $releasever - RPMforge.net - dag
baseurl = http://apt.sw.be/redhat/el6/en/$basearch/rpmforge
mirrorlist = http://mirrorlist.repoforge.org/el6/mirrors-rpmforge
#mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge
enabled = 1
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 1

[rpmforge-extras]
name = RHEL $releasever - RPMforge.net - extras
baseurl = http://apt.sw.be/redhat/el6/en/$basearch/extras
mirrorlist = http://mirrorlist.repoforge.org/el6/mirrors-rpmforge-extras
#mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge-extras
enabled = 0 ####### CHANGE THIS LINE TO "enabled = 1" #############
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 1

[rpmforge-testing]
name = RHEL $releasever - RPMforge.net - testing
baseurl = http://apt.sw.be/redhat/el6/en/$basearch/testing
mirrorlist = http://mirrorlist.repoforge.org/el6/mirrors-rpmforge-testing
#mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge-testing
enabled = 0
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 1

Once you've done this, then you can update git with

yum update git

I'm not sure why, but they then suggest disabling rpmforge-extras (change back to enabled = 0) and then running yum clean all.

Most likely you'll need to use sudo for these commands.

Rob Watts
  • 6,866
  • 3
  • 39
  • 58
  • Really great answer! Solved my issues on Redhat (RHEL) 6.3. – Max Feb 04 '15 at 10:52
  • Instead of manually editing the repo file twice (first enable extras and then disable it again), I just ran `yum install --enablerepo=rpmforge-extras git` and that dit it! – alleen1 Mar 06 '19 at 09:33
6

I was able to get a git 1.7.1 to work after quite some time.

First, I had to do disable SSL just so I could pull:

git config --global http.sslverify false

Then I could clone

git clone https://github.com/USERNAME/PROJECTNAME.git

Then after adding and committing i was UNABLE to push back. So i did

git remote -v

origin  https://github.com/USERNAME/PROJECTNAME.git (fetch)
origin  https://github.com/USERNAME/PROJECTNAME.git (push)

to see the pull and push adresses:

These must be modified with USERNAME@

git remote set-url origin https://USERNAME@github.com/USERNAME/PROJECTNAME.git

It will still prompt you for a password, which you could add with

USERNAME:PASSWORD@github.....

But dont do that, as you save your password in cleartext for easy theft.

I had to do this combination since I could not get SSH to work due to firewall limitations.

Heine Nørby
  • 61
  • 1
  • 2
5

This is the dumbest answer to this question, but check the status of GitHub. This one got me :)

BenDundee
  • 4,389
  • 3
  • 28
  • 34
  • Message from today: "We are still working to mitigate a very large DDoS attack. The site is now available for some users but we will remain in red status until we're confident the site is staying up." Who hacks GitHub? Really? – BenDundee Aug 15 '13 at 16:28
  • obviously not homakov, he commits to master instead of DDoS – nurettin Sep 17 '13 at 06:08
4

I had the same problem and error. In my case it was the https_proxy not set. Setting the https_proxy environment variable fixed the issue.

$ export https_proxy=https://<porxy_addres>:<proxy_port>

Example:

$ export https_proxy=https://my.proxy.company.com:8000

Hope this help somebody.