533

Note: while the use-case described is about using submodules within a project, the same applies to a normal git clone of a repository over HTTP.

I have a project under Git control. I'd like to add a submodule:

git submodule add http://github.com/jscruggs/metric_fu.git vendor/plugins/metric_fu

But I get

...
got 1b0313f016d98e556396c91d08127c59722762d0
got 4c42d44a9221209293e5f3eb7e662a1571b09421
got b0d6414e3ca5c2fb4b95b7712c7edbf7d2becac7
error: Unable to find abc07fcf79aebed56497e3894c6c3c06046f913a under http://github.com/jscruggs/metri...
Cannot obtain needed commit abc07fcf79aebed56497e3894c6c3c06046f913a
while processing commit ee576543b3a0820cc966cc10cc41e6ffb3415658.
fatal: Fetch failed.
Clone of 'http://github.com/jscruggs/metric_fu.git' into submodule path 'vendor/plugins/metric_fu'

I have my HTTP_PROXY set up:

c:\project> echo %HTTP_PROXY%
http://proxy.mycompany:80

I even have a global Git setting for the http proxy:

c:\project> git config --get http.proxy
http://proxy.mycompany:80

Has anybody gotten HTTP fetches to consistently work through a proxy? What's really strange is that a few project on GitHub work fine (awesome_nested_set for example), but others consistently fail (rails for example).

kenorb
  • 155,785
  • 88
  • 678
  • 743
James A. Rosen
  • 64,193
  • 61
  • 179
  • 261
  • Could your proxy be censoring some words or something, thereby only affecting those repos where those words happen to show up as part of the byte stream? – pjz Sep 24 '08 at 16:21
  • 9
    possible duplicate of [Getting git to work with a proxy server](http://stackoverflow.com/questions/783811/getting-git-to-work-with-a-proxy-server) – alvaro Aug 10 '14 at 13:12
  • 6
    @alvaro, I think you mean that [Getting git to work with a proxy server](http://stackoverflow.com/questions/783811/getting-git-to-work-with-a-proxy-server) is a possible duplicate of this question. This question is older than the one to which you refer. – Derek Mahar Jul 11 '15 at 17:05
  • 2
    @James, your "global" Git setting for the proxy server is not actually global, but local. To be global, you need to supply argument `--global` to `git config`. – Derek Mahar Jul 11 '15 at 22:50
  • And just in case if anybody would wonder why would git ignore proxy settings: make sure you're working with the address *not* with git protocol, i.e. change **git**://github.com/SomeProject/foo.git → **https**://github.com/SomeProject/foo.git – Hi-Angel Jul 25 '16 at 09:52
  • 1
    @DerekMahar Older questions may be closed of duplicates of newer questions, if the newer question is better quality (or more generally applicatble). – Raedwald Feb 16 '17 at 14:19

30 Answers30

634

You can also set the HTTP proxy that Git uses in global configuration property http.proxy:

git config --global http.proxy http://proxy.mycompany:80

To authenticate with the proxy:

git config --global http.proxy http://mydomain\\myusername:mypassword@myproxyserver:8080/

(Credit goes to @EugeneKulabuhov and @JaimeReynoso for the authentication format.)

Derek Mahar
  • 27,608
  • 43
  • 124
  • 174
  • 8
    This worked for me: Set HTTP_PROXY in environment for user (on Windows), then the above comment with $HTTP_PROXY (uppercase). +1 for this solution. – Sean Aitken Jun 29 '11 at 15:42
  • 4
    CleverCoder, on Windows, you need to specify %HTTP_PROXY%, not $HTTP_PROXY (unless you're running Cygwin, of course). I will edit my answer to work in Windows instead of a Unix environment. – Derek Mahar Aug 25 '11 at 14:11
  • 28
    Use `git config --global http.proxy http://mydomain\\myusername:mypassword@myproxyserver:8080` syntax to provide username/password – Eugene Kulabuhov Dec 03 '14 at 14:33
  • @JFA, I'm not sure I completely agree with your edit. Yes, the command you added does work on a Linux system, but the original question referred not to Linux, but to Windows. – Derek Mahar Jul 10 '15 at 14:03
  • @DerekMahar I don't see anything saying windows in the original post, but also, I reached this question from Google, saw that you used to have a linux answer, but deleted it, and had to search through the edits to find the difference, so my though was that if you already have the linux answer, and this question is getting a massive amount of traffic, you might as well have a multisystem solution. – jfa Jul 10 '15 at 14:44
  • @JFA, the question doesn't mention Windows directly, but implies Windows because it refers to Windows drive letters. – Derek Mahar Jul 10 '15 at 15:00
  • @JFA, it's also important to point out that in order for your Linux command to work, the user must define environment variable `http_proxy`. The question clearly states that Windows environment variable `HTTP_PROXY` is defined which is why the Windows part of the answer refers to `%HTTP_PROXY%`. We cannot make the same assumption about shell variable `http_proxy`. – Derek Mahar Jul 11 '15 at 16:52
  • @JFA, I edited the answer so that it explicitly sets the environment variables before they are used. – Derek Mahar Jul 11 '15 at 17:25
  • 2
    For anyone who might be having problems with the proxy, http://:@:/ worked for me – Jaime Reynoso Mar 30 '16 at 13:33
  • 1
    @Mr.Hyde, see http://stackoverflow.com/questions/11265463/reset-git-proxy-to-default-configuration. – Derek Mahar May 09 '16 at 01:29
  • @DerekMahar, I don't want to sound "picky" but the first command in the "Linux" section of your answer does not set an **environment (or global) variable**. It sets a local shell variable. I mention this as _git_ uses _curl_ to fetch data over http(s) and _curl_ can be directed using environment variables to use a proxy. Strangely, to specify the http proxy, _curl_ accepts the **http_proxy** environment variable in lowercase only. Therefore I think your answer and comment might be misleading to people that are looking for an answer to set the environment variable to make _git_ use a proxy. – Daniel K. Nov 30 '16 at 10:06
  • @DanielK., thank you for explaining why James A. Rosen's answer (http://stackoverflow.com/a/397642/107158) works! I hadn't known that *curl* reads lowercase environment variable `http_proxy`. The reason I used the local shell variables was not to be misleading, but to refer to the original question which refers to `%HTTP_PROXY%` and because JFA edited my answer to include a Windows specific solution that also referred to `%HTTP_PROXY%`. – Derek Mahar Nov 30 '16 at 15:15
  • However, since the Windows and Linux solutions differ only in the format of variable `HTTP_PROXY`, and this variable is not essential to the answer and adds only redundant information, I will merge the two commands together into a single, platform agnostic command. – Derek Mahar Nov 30 '16 at 15:15
  • One most important thing is that even using this, or $http_proxy, it only works when cloning with `https`, not with `ssh`!! That's what took me so long to find out. Hope it helps others with it – imans77 Feb 09 '20 at 00:58
151

There's some great answers on this already. However, I thought I would chip in as some proxy servers require you to authenticate with a user Id and password. Sometimes this can be on a domain.

So, for example if your proxy server configuration is as follows:

Server: myproxyserver
Port: 8080
Username: mydomain\myusername
Password: mypassword

Then, add to your .gitconfig file using the following command:

git config --global http.proxy http://mydomain\\myusername:mypassword@myproxyserver:8080

Don't worry about https. As long as the specified proxy server supports http, and https, then one entry in the config file will suffice.

You can then verify that the command added the entry to your .gitconfig file successfully by doing cat .gitconfig:

At the end of the file you will see an entry as follows:

[http]
    proxy = http://mydomain\\myusername:mypassword@myproxyserver:8080

That's it!

Max MacLeod
  • 26,115
  • 13
  • 104
  • 132
  • Interesting. I am able to get to the "Resolving deltas" portion with 100% but then it looks like the clone process just hangs. Anyone experienced that? – Roman Apr 30 '13 at 22:31
  • 1
    +1. And soon, you will be able [to setup proxy per url!](http://stackoverflow.com/a/18712501/6309) – VonC Sep 10 '13 at 07:01
  • @apoplexy can you comment on your suggested edit please so I can consider – Max MacLeod Jan 16 '14 at 14:27
  • 3
    If you have @ symbol in your username or password, then you can URL encode it `%40` and it will work. – Adarsha Dec 11 '15 at 06:14
  • 3
    Instead of cat .gitconfig, you can list the config settings with git config --list –  Feb 26 '18 at 12:19
138

What finally worked was setting the http_proxy environment variable. I had set HTTP_PROXY correctly, but git apparently likes the lower-case version better.

Derek Mahar
  • 27,608
  • 43
  • 124
  • 174
James A. Rosen
  • 64,193
  • 61
  • 179
  • 261
66

If you just want to use proxy on a specified repository, don't need on other repositories. The preferable way is the -c, --config <key=value> option when you git clone a repository. e.g.

$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git --config "http.proxy=proxyHost:proxyPort"
alijandro
  • 11,627
  • 2
  • 58
  • 74
  • This is strange, I tried setting $http_proxy, but git didn't respect it. Looks like it only cares about its own config... – weberc2 Feb 24 '15 at 14:24
  • Works. You can also specify `--config` multiple times, e.g. when you also want to set `https.proxy`. – barfuin Mar 30 '15 at 07:36
  • 5
    clone with proxy config but without changing the proxy config of the user. Exactly what I need ! Thx. – doom Mar 21 '18 at 12:36
  • --config "core.gitProxy..." howto,I want to proxy ssh protocol without global proxy seting, thx.@alijandro – Carson Feb 12 '21 at 14:14
55

It looks like you're using a mingw compile of Git on windows (or possibly another one I haven't heard about). There are ways to debug this: I believe all of the http proxy work for git is done by curl. Set this environment variable before running git:

GIT_CURL_VERBOSE=1

This should at least give you an idea of what is going on behind the scenes.

sethbc
  • 3,441
  • 1
  • 16
  • 9
  • 7
    When I add this environment variable, msysgit doesn't print out anything extra. :( – Andrew Arnott Mar 29 '09 at 23:22
  • after fighting with proxies for some time, this tip helped me find out that curl's cert database was missing/messed up, and THAT was why requests were failing. – davenpcj Jul 17 '13 at 19:38
26

When your network team does ssl-inspection by rewriting certificates, then using a http url instead of a https one, combined with setting this var worked for me.

git config --global http.proxy http://proxy:8081
bbaassssiiee
  • 6,013
  • 2
  • 42
  • 55
  • 2
    You can also add this to the environment to accept the rewritten certificates that the network dudes offer to inspect your traffic: export GIT_SSL_NO_VERIFY=true – bbaassssiiee Apr 12 '13 at 09:04
  • Worked for me perfectly. Thanks. I just had to add git config --global http.proxy http://proxy:8081 git config --global https.proxy http://proxy:8081 – Sid Apr 29 '13 at 12:06
  • 1
    Thanks to @sethbc, @datasmid! I needed GIT_CURL_VERBOSE=1 to debug and GIT_SSL_NO_VERIFY=true to skip the verification. – Henry Rivera Oct 02 '15 at 19:55
  • not working with me. not even with the GIT_SSL_NO_VERIFY var – keinabel May 16 '17 at 08:31
21

For me the git:// just doesn't work through the proxy although the https:// does. This caused some bit of headache because I was running scripts that all used git:// so I couldn't just easily change them all. However I found this GEM

git config --global url."https://github.com/".insteadOf git://github.com/
legoscia
  • 39,593
  • 22
  • 116
  • 167
  • I know that I also had problems to pull from git://. Have you considered a SSH key problem? My problem was due to a bad SSH key configuration. – avazula May 17 '18 at 09:22
20

You could too edit .gitconfig file located in %userprofile% directory on Windows system (notepad %userprofile%.gitconfig) or in ~ directory on Linux system (vi ~/.gitconfig) and add a http section as below.

Content of .gitconfig file :

[http]
        proxy = http://proxy.mycompany:80
Stéphane B.
  • 3,260
  • 2
  • 30
  • 35
17

This is an old question but if you are on Windows, consider setting HTTPS_PROXY as well if you are retrieving via an https URL. Worked for me!

Benjamin Wootton
  • 2,089
  • 20
  • 21
  • 2
    It was enough to set `https_proxy` environment variable alone (no git global or repo proxy option set) in my case (msysgit on Windows XP). – Piotr Dobrogost Mar 05 '12 at 15:23
14

I find neither http.proxy nor GIT_PROXY_COMMAND work for my authenticated http proxy. The proxy is not triggered in either way. But I find a way to work around this.

  1. Install corkscrew, or other alternatives you want.
  2. Create a authfile. The format for authfile is: user_name:password, and user_name, password is your username and password to access your proxy. To create such a file, simply run command like this: echo "username:password" > ~/.ssh/authfile.

  3. Edit ~/.ssh/config, and make sure its permission is 644: chmod 644 ~/.ssh/config

Take github.com as an example, add the following lines to ~/.ssh/config:

Host    github.com
        HostName        github.com
        ProxyCommand    /usr/local/bin/corkscrew <your.proxy> <proxy port> %h %p <path/to/authfile>
        User            git

Now whenever you do anything with git@github.com, it will use the proxy automatically. You can easily do the same thing to Bitbucket as well.

This is not so elegant as other approaches, but it works like a charm.

Carlosin
  • 509
  • 6
  • 9
  • 1
    Can you please elaborate on step 2, "create a authfile"? It seems like your approach is the only one that will work for git:// urls. – nik Oct 31 '13 at 00:20
11

On Windows, if you don't want to put your password in .gitconfig in the plain text, you can use

It authenticates you against normal or even Windows NTLM proxy and starts localhost-proxy without authentication.

In order to get it run:

  • Install Cntml
  • Configure Cntml according to documentation to pass your proxy authentication
  • Point git to your new localhost proxy:

    [http]
        proxy = http://localhost:3128       # change port as necessary
    
Boris Brodski
  • 8,425
  • 4
  • 40
  • 55
  • 2
    For what it's worth, this should've been the accepted answer, he's on windows. There isn't a transparent proxy (otherwise there would not be a problem. – booyaa Mar 26 '15 at 11:47
9

For me what it worked was:

sudo apt-get install socat

Create a file inside your $BIN_PATH/gitproxy with:

#!/bin/sh 
_proxy=192.168.192.1 
_proxyport=3128 
exec socat STDIO PROXY:$_proxy:$1:$2,proxyport=$_proxyport

Dont forget to give it execution permissions

chmod a+x gitproxy

Run following commands to setup environment:

export PATH=$BIN_PATH:$PATH
git config --global core.gitproxy gitproxy
Lesswire
  • 829
  • 9
  • 11
  • 1
    Link to an explanation and a link to a gist with updates to the (mini-)script: http://www.emilsit.net/blog/archives/how-to-use-the-git-protocol-through-a-http-connect-proxy/ – Kalle Richter Jun 27 '15 at 12:09
  • This answer is the only one that works for `git://` protocol URLs, for those (rare) git servers that don't support https. Also works on windows, with an appropriate batch file and socat for windows. – davenpcj Jun 29 '16 at 14:42
9

Set Git credential.helper to wincred.

git config --global credential.helper wincred

Make sure there is only 1 credential.helper

git config -l

If there is more than 1 and it's not set to wincred remove it.

git config --system --unset credential.helper

Now set the proxy with no password.

git config --global http.proxy http://<YOUR WIN LOGIN NAME>@proxy:80

Check that all the settings that you added looks good....

git config --global -l

Now you good to go!

Thor88
  • 323
  • 3
  • 7
8

Setup proxy to git

command

git config --global http.proxy http://user:password@domain:port

example

git config --global http.proxy http://clairton:123456@proxy.clairtonluz.com.br:8080
Clairton Luz
  • 2,116
  • 19
  • 15
6

This worked to me.

git config --global http.proxy proxy_user:proxy_passwd@proxy_ip:proxy_port
noufalcep
  • 3,446
  • 15
  • 33
  • 51
Vagner Nogueira
  • 131
  • 2
  • 5
6

I had the same problem, with a slightly different fix: REBUILDING GIT WITH HTTP SUPPORT

The git: protocol did not work through my corporate firewall.

For example, this timed out:

git clone git://github.com/miksago/node-websocket-server.git

curl github.com works just fine, though, so I know my http_proxy environment variable is correct.

I tried using http, like below, but got an immediate error.

git clone http://github.com/miksago/node-websocket-server.git

->>>  fatal: Unable to find remote helper for 'http' <<<-

I tried recompiling git like so:

./configure  --with-curl --with-expat

but still got the fatal error.

Finally, after several frustrating hours, I read the configure file, and saw this:

# Define CURLDIR=/foo/bar if your curl header and library files are in

# /foo/bar/include and /foo/bar/lib directories.

I remembered then, that I had not complied curl from source, and so went looking for the header files. Sure enough, they were not installed. That was the problem. Make did not complain about the missing header files. So I did not realize that the --with-curl option did nothing (it is, in fact the default in my version of git).

I did the following to fix it:

  1. Added the headers needed for make:

    yum install curl-devel
    (expat-devel-1.95.8-8.3.el5_5.3.i386  was already installed).
    
  2. Removed git from /usr/local (as I want the new install to live there).

    I simply removed git* from /usr/local/share and /usr/local/libexec

  3. Searched for the include dirs containing the curl and expat header files, and then (because I had read through configure) added these to the environment like so:

    export CURLDIR=/usr/include 
    export EXPATDIR=/usr/include
    
  4. Ran configure with the following options, which, again, were described in the configure file itself, and were also the defaults but what the heck:

    ./configure  --with-curl --with-expat
    
  5. And now http works with git through my corporate firewall:

    git clone http://github.com/miksago/node-websocket-server.git
    Cloning into 'node-websocket-server'...
    * Couldn't find host github.com in the .netrc file, using defaults
    * About to connect() to proxy proxy.entp.attws.com port 8080
    *   Trying 135.214.40.30... * connected
    ...
    
Kalle Richter
  • 8,008
  • 26
  • 77
  • 177
steve98177
  • 2,121
  • 2
  • 14
  • 6
  • I'd glad you put this one forward, I didn't realise that the git protocol wasn't being handled on my squid proxy – rupert160 May 27 '20 at 03:51
5

Just to post this as it is the first result on Google, this blog post I found solves the problem for me by updated the curl certificates.

http://www.simplicidade.org/notes/archives/2011/06/github_ssl_ca_errors.html

RishiD
  • 2,098
  • 2
  • 26
  • 24
  • 1
    Halleluyah, this plus `git config --global http.sslcainfo NEW_CERTS_BUNDLE.crt` as described in: http://stackoverflow.com/a/8248484/98528 did it for me! Thanks! – akavel May 23 '12 at 14:27
4

Use proxychains

proxychains git pull ...

update: proxychains is discontinued, use proxychains-ng instead.

Fangxing
  • 5,716
  • 2
  • 49
  • 53
4

Worth to mention: Most examples on the net show examples like

git config --global http.proxy proxy_user:proxy_passwd@proxy_ip:proxy_port

So it seems, that - if your proxy needs authentication - you must leave your company-password in the git-config. Which isn't really cool.

But, if you just configure the user without password:

git config --global http.proxy proxy_user@proxy_ip:proxy_port

Git seems (at least on my Windows-machine without credentials-helper) to recognize that and prompts for the proxy-password on repo-access.

gratinierer
  • 1,748
  • 1
  • 10
  • 10
  • You are my man, as my sso company username and password have so much special simboles that was quite impossibile to encode and get through. With this "escamotage" I was able to provide the password on the clone face or any other next steps after have set the proxy address. – Carmine Tambascia Mar 10 '20 at 12:25
3

you can use:

git config --add http.proxy http://user:password@proxy_host:proxy_port
Montells
  • 6,389
  • 4
  • 48
  • 53
3

The below method works for me:

echo 'export http_proxy=http://username:password@roxy_host:port/' >> ~/.bash_profile
echo 'export https_proxy=http://username:password@roxy_host:port' >> ~/.bash_profile
  • Zsh note: Modify your ~/.zshenv file instead of ~/.bash_profile.
  • Ubuntu and Fedora note: Modify your ~/.bashrc file instead of ~/.bash_profile.
Nguyen Van Duc
  • 1,019
  • 10
  • 9
3

There is a way to set up a proxy for a specific URL, see the http.<url>.* section in the git config manual. For example, for https://github.com/ one can do

git config --global 'http.https://github.com/.proxy' http://proxy.mycompany:80
Rosen Matev
  • 1,828
  • 19
  • 20
2

For Windows

Goto --> C:/Users/user_name/gitconfig

Update gitconfig file with below details

[http]

[https]

proxy = https://your_proxy:your_port

[http]

proxy = http://your_proxy:your_port

How to check your proxy and port number?

Internet Explorer -> Settings -> Internet Options -> Connections -> LAN Settings

School Boy
  • 1,207
  • 2
  • 19
  • 33
1

This isn't a problem with your proxy. It's a problem with github (or git). It fails for me on git-1.6.0.1 on linux as well. Bug is already reported (by you no less).

Make sure to delete your pasties, they're already on google. Edit: Must've been dreaming, i guess you can't delete them. Use Gist instead?

sethbc
  • 3,441
  • 1
  • 16
  • 9
  • I posted to github and msysGit as well b/c I wasn't sure where the problem lay. I can't seem to delete pasties, unfortunately. – James A. Rosen Sep 24 '08 at 19:37
1

$http_proxy is for http://github.com.... $https_proxy is for https://github.com...

jimagic
  • 31
  • 3
1

The above answers worked for me when my proxy doesn't need authentication. If you are using proxy which requires you to authenticate then you may try CCProxy. I have small tutorial on how to set it up here,

http://blog.praveenkumar.co.in/2012/09/proxy-free-windows-xp78-and-mobiles.html

I was able to push, pull, create new repos. Everything worked just fine. Make sure you do a clean uninstall and reinstall of new version if you are facing issues with Git like I did.

Praveen
  • 393
  • 4
  • 10
0

I got around the proxy using https... some proxies don't even check https.

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

c:\git\meantest>git clone http://github.com/linnovate/mean.git
Cloning into 'mean'...
fatal: unable to access 'http://github.com/linnovate/mean.git/': Failed connect
to github.com:80; No error

c:\git\meantest>git clone https://github.com/linnovate/mean.git
Cloning into 'mean'...
remote: Reusing existing pack: 2587, done.
remote: Counting objects: 27, done.
remote: Compressing objects: 100% (24/24), done.
rRemote: Total 2614 (delta 3), reused 4 (delta 0)eceiving objects:  98% (2562/26

Receiving objects: 100% (2614/2614), 1.76 MiB | 305.00 KiB/s, done.
Resolving deltas: 100% (1166/1166), done.
Checking connectivity... done
ndsmyter
  • 6,535
  • 3
  • 22
  • 37
Rob Koch
  • 1,523
  • 3
  • 18
  • 26
0

As this was answered by many but This is just for Winodws USER who is behind proxy with auth.

Re-Installing(first failed, Don't remove).

Goto ->
**Windows**
1. msysgit\installer-tmp\etc\gitconfig
    Under [http]
        proxy = http://user:pass@url:port

**Linux**
1. msysgit\installer-tmp\setup-msysgit.sh
      export HTTP_PROXY="http://USER:PASS@proxy.abc.com:8080"

if you have any special char in user/pass use url_encode

Community
  • 1
  • 1
Ravi Parekh
  • 5,253
  • 9
  • 46
  • 58
0

as @user2188765 has already pointed out, try replacing the git:// protocol of the repository with http[s]://. See also this answer

Community
  • 1
  • 1
DomTomCat
  • 8,189
  • 1
  • 49
  • 64
0

Recently . if I use git clone with http addr .

 git clone --config "http.proxy=http://<ip>:<port>" https://github.com/<username>/<reponame>.git

GitHub will require for username and passwd.
and then says this auth method is no longer use because not safe.

So , if I use ssh method to git clone . things will work.
noticed that . ssh will not work like this :

 git clone --config "http.proxy=http://<ip>:<port>" git@github.com:<username>/<reponame>.git

ssh with proxy work like this:

# edit ~/.ssh/config and paste the text below:
Host github.com
    Hostname ssh.github.com
    Port 443
    ProxyCommand nc -X connect -x <ip>:<port> %h %p

after edit config file .
ssh proxy will work :

git clone git@github.com:<username>/<reponame>.git

mention that config file .
I dont understand why its 443 port instead of 22. just GPT4 told me . and it works for me ~

q2333
  • 33
  • 1
  • 6