How do I pull from a Git repository through an HTTP proxy?
Asked Answered
A

30

540

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).

Attenuator answered 24/9, 2008 at 15:58 Comment(6)
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?Ferrotype
possible duplicate of Getting git to work with a proxy serverBushwhacker
@alvaro, I think you mean that 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.Downe
@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.Downe
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.gitDupaix
@DerekMahar Older questions may be closed of duplicates of newer questions, if the newer question is better quality (or more generally applicatble).Mediocrity
A
139

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.

Attenuator answered 29/12, 2008 at 12:34 Comment(9)
Does setting http.proxy in the global Git configuration work? In your question, you set http.proxy in the local repository configuration.Downe
In my case I had to set the https_proxyPremature
https.proxy seemed to work for me as I was using https over githubRokach
@MSmith If you had to set https_proxy this means you were using https not http which question is about.Czech
Curl and libcurl don't recognize uppercase HTTP_PROXY and HTTPS_PROXY. See this link for more info: curl.haxx.se/mail/archive-2001-12/0034.htmlFloating
set $all_proxy environment variable is also ok.Fideicommissary
The "$http_proxy" environment variable is the http_proxy environment variable.Donniedonnish
Didn't work for me. On the other hand, the solution from user 'Max MacLeod' worked (git config --global http.proxy mydomain...).Anacreontic
Failed for me with: "The requested URL returned error: 501"Bootle
D
639

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.)

Downe answered 4/8, 2010 at 14:55 Comment(14)
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.Subphylum
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.Downe
Use git config --global http.proxy http://mydomain\\myusername:mypassword@myproxyserver:8080 syntax to provide username/passwordSubtangent
@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.Downe
@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.Clamper
@JFA, the question doesn't mention Windows directly, but implies Windows because it refers to Windows drive letters.Downe
@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.Downe
@JFA, I edited the answer so that it explicitly sets the environment variables before they are used.Downe
For anyone who might be having problems with the proxy, http://<UserID>:<Password>@<ProxyURL>:<Port>/ worked for meMontagnard
@Mr.Hyde, see stackoverflow.com/questions/11265463/….Downe
@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.Brittne
@DanielK., thank you for explaining why James A. Rosen's answer (https://mcmap.net/q/13487/-how-do-i-pull-from-a-git-repository-through-an-http-proxy) 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%.Downe
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.Downe
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 itDwelling
A
152

There are 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 configuration 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!

Ardent answered 7/2, 2013 at 11:33 Comment(5)
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?Rash
+1. And soon, you will be able to setup proxy per url!Benedetta
@apoplexy can you comment on your suggested edit please so I can considerArdent
If you have @ symbol in your username or password, then you can URL encode it %40 and it will work.Dentate
Instead of cat .gitconfig, you can list the config settings with git config --listPhilipps
A
139

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.

Attenuator answered 29/12, 2008 at 12:34 Comment(9)
Does setting http.proxy in the global Git configuration work? In your question, you set http.proxy in the local repository configuration.Downe
In my case I had to set the https_proxyPremature
https.proxy seemed to work for me as I was using https over githubRokach
@MSmith If you had to set https_proxy this means you were using https not http which question is about.Czech
Curl and libcurl don't recognize uppercase HTTP_PROXY and HTTPS_PROXY. See this link for more info: curl.haxx.se/mail/archive-2001-12/0034.htmlFloating
set $all_proxy environment variable is also ok.Fideicommissary
The "$http_proxy" environment variable is the http_proxy environment variable.Donniedonnish
Didn't work for me. On the other hand, the solution from user 'Max MacLeod' worked (git config --global http.proxy mydomain...).Anacreontic
Failed for me with: "The requested URL returned error: 501"Bootle
O
70

If you just want to use a proxy on a specified repository, and 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"
Optometer answered 24/12, 2014 at 1:45 Comment(4)
This is strange, I tried setting $http_proxy, but git didn't respect it. Looks like it only cares about its own config...Rimple
Works. You can also specify --config multiple times, e.g. when you also want to set https.proxy.Maximilien
clone with proxy config but without changing the proxy config of the user. Exactly what I need ! Thx.Musculature
--config "core.gitProxy..." howto,I want to proxy ssh protocol without global proxy seting, thx.@OptometerIcterus
M
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.

Martinsen answered 24/9, 2008 at 16:24 Comment(2)
When I add this environment variable, msysgit doesn't print out anything extra. :(Facesaving
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.Guadalcanal
E
26

When your network team does SSL inspection by rewriting certificates, then using an HTTP URL instead of an HTTPS one, combined with setting this variable worked for me.

git config --global http.proxy http://proxy:8081
Evangelina answered 11/3, 2013 at 15:10 Comment(4)
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=trueEvangelina
Worked for me perfectly. Thanks. I just had to add git config --global http.proxy proxy:8081 git config --global https.proxy proxy:8081Antalkali
Thanks to @sethbc, @datasmid! I needed GIT_CURL_VERBOSE=1 to debug and GIT_SSL_NO_VERIFY=true to skip the verification.Becnel
not working with me. not even with the GIT_SSL_NO_VERIFY varArcherfish
D
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/
Dayna answered 23/9, 2015 at 16:30 Comment(1)
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.Mumps
J
20

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

Content of the .gitconfig file:

[http]
        proxy = http://proxy.mycompany:80
Jillion answered 19/10, 2012 at 8:35 Comment(0)
D
18

If you are on Windows, consider setting HTTPS_PROXY as well if you are retrieving via an https URL. It worked for me!

Division answered 19/4, 2011 at 11:51 Comment(1)
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).Czech
M
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 [email protected], 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.

Malcah answered 28/5, 2013 at 14:21 Comment(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.Freewheel
J
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 number as necessary
    
Janicejanicki answered 20/2, 2014 at 9:46 Comment(1)
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.Dashpot
F
11

Set Git credential.helper to wincred.

git config --global credential.helper wincred

Make sure there is only one credential.helper

git config -l

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

git config --system --unset credential.helper

Now set the proxy without any 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 are good to go!

Franfranc answered 15/8, 2018 at 23:31 Comment(0)
E
9

For me this worked:

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

Don’t forget to give it execution permissions:

chmod a+x gitproxy

Run the following commands to set up the environment:

export PATH=$BIN_PATH:$PATH
git config --global core.gitproxy gitproxy
Erudite answered 9/4, 2015 at 9:23 Comment(2)
Link to an explanation and a link to a gist with updates to the (mini-)script: emilsit.net/blog/archives/…Skidmore
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.Guadalcanal
S
8

Set up proxy to Git

Command

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

Example

git config --global http.proxy http://clairton:[email protected]:8080
Schoolmarm answered 24/11, 2016 at 13:21 Comment(0)
N
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 I 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 I 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`
  1. Searched for the include directories 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

  2. 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

  3. 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 ...
Needful answered 26/2, 2012 at 2:13 Comment(1)
I'd glad you put this one forward, I didn't realise that the git protocol wasn't being handled on my squid proxyDenny
A
6

This worked to me.

git config --global http.proxy proxy_user:proxy_passwd@proxy_ip:proxy_port
Apicella answered 24/10, 2016 at 3:22 Comment(0)
H
5

This blog post I found solves the problem for me by updating the curl certificates.

GitHub, CA errors and old curl's

Halloo answered 26/8, 2011 at 14:56 Comment(1)
Halleluyah, this plus git config --global http.sslcainfo NEW_CERTS_BUNDLE.crt as described in: https://mcmap.net/q/13740/-getting-git-to-work-with-a-proxy-server-fails-with-quot-request-timed-out-quot did it for me! Thanks!Toweling
W
4

Use proxychains

proxychains git pull ...

But proxychains is discontinued. Use proxychains-ng instead.

Willful answered 22/3, 2017 at 14:52 Comment(2)
unfortunately Unix onlyVicar
@Vicar Jun, for windows your may want try SocksCap64Willful
H
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.

Hades answered 11/12, 2019 at 9:36 Comment(1)
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.Thebaid
M
3

You can use:

git config --add http.proxy http://user:password@proxy_host:proxy_port
Micky answered 21/2, 2017 at 17:29 Comment(0)
H
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.
Hardan answered 27/11, 2019 at 4:11 Comment(0)
C
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
Cowpox answered 31/3, 2021 at 14:28 Comment(0)
A
2

For Windows

Go to → C:/Users/user_name/gitconfig

Update the gitconfig file with the below details:

[http]

[https]

    proxy = https://your_proxy:your_port

[http]

    proxy = http://your_proxy:your_port

How can you check your proxy and port number?

Internet ExplorerSettingsInternet OptionsConnectionsLAN Settings

Atworth answered 2/2, 2016 at 8:50 Comment(0)
M
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. But I guess you can't delete them. Use Gist instead?

Martinsen answered 24/9, 2008 at 19:2 Comment(1)
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.Attenuator
H
1

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

Haynor answered 19/4, 2013 at 7:27 Comment(0)
C
1

The previous answers worked for me when my proxy didn'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 repositories. 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.

Cathead answered 10/8, 2013 at 1:40 Comment(1)
The link is broken: "Hmm. We’re having trouble finding that site. We can’t connect to the server at blog.praveenkumar.co.in."Mcclung
D
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
Displume answered 19/3, 2014 at 16:58 Comment(0)
F
0
      export HTTP_PROXY="http://USER:[email protected]:8080"

If you have any special characters in the user/password use url_encode.

Full answered 2/3, 2016 at 15:5 Comment(0)
I
0

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

Ibadan answered 7/4, 2016 at 8:5 Comment(0)
P
0

Recently, if I use Git clone with an HTTP address,

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

GitHub will require a username and password. And then it says this authentication method is no longer used, because it is not safe.

So, if I use the SSH method to Git clone, things will work. I noticed that SSH will not work like this:

git clone --config "http.proxy=http://<ip>:<port>" [email protected]:<username>/<reponame>.git

SSH with a proxy works 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 editing the config file, the SSH proxy will work:

git clone [email protected]:<username>/<reponame>.git

mention that configuration file.

I don’t understand why it’s 443 port instead of 22. Just ChatGPT (using GPT-4) told me, and it works for me.

Phonotypy answered 13/8, 2023 at 6:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.