How do I get Git to use a proxy server?
I need to check out code from a Git server, but it shows \"Request timed out\" every time. How do I get around this?
I work on Windows XP at work(state/gov), so I did my research and found this here and it worked for me. Hope this helps :)
The http_proxy Environment Variable
If you use a proxy server or firewall, you may need to set the http_proxy environment variable in order to access some url from commandline. Example : Installing ppm for perl or applying rpm in linux ,updating ubuntu
Set the http_proxy variable with the hostname or IP address of the proxy server: http_proxy=http:// [proxy.example.org]
If the proxy server requires a user name and password, include them in the following form: http_proxy=http:// [username:password@proxy.example.org]
If the proxy server uses a port other than 80, include the port number: http_proxy=http:// [username:password@proxy.example.org:8080]
Windows XP
- Open the Control Panel and click the System icon.
- On the Advanced tab, click on Environment Variables.
- Click New in the System variables panel.
- Add http_proxy with the appropriate proxy information (see examples above).
Linux, Solaris or HP-UX
Set the http_proxy environment variable using the command specific to your shell (e.g. set or export). To make this change persistent, add the command to the appropriate profile file for the shell. For example, in bash, add a line like the following to your .bash_profile or .bashrc file:
- http_proxy=http:// [username:password@hostname:port];
- export $http_proxy
After tirelessly trying every solution on this page, my work around was to use and SSH key instead!
I followed the most of the answers which was recommended here. First I got the following error:
fatal: unable to access 'https://github.com/folder/sample.git/': schannel: next InitializeSecurityContext failed: Unknown error (0x80092012) - The revocation function was unable to check revocation for the certificate.
Then I have tried the following command by @Salim Hamidi
git config --global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080
But I got the following error:
fatal: unable to access 'https://github.com/folder/sample.git/': Received HTTP code 407 from proxy after CONNECT
This could happen if the proxy server can't verify the SSL certificate. So we want to make sure that the ssl verification is off (not recommended for non trusted sites), so I have done the following steps which was recommended by @Arpit but with slight changes:
1.First make sure to remove any previous proxy settings:
git config --global --unset http.proxy
2.Then list and get the gitconfig content
git config --list --show-origin
3.Last update the content of the gitconfig file as below:
[http]
sslCAInfo = C:/yourfolder/AppData/Local/Programs/Git/mingw64/ssl/certs/ca-bundle.crt
sslBackend = schannel
proxy = http://proxyuser:proxypwd@proxy.server.com:8080
sslverify = false
[https]
proxy = http://proxyuser:proxypwd@proxy.server.com:8080
sslverify = false
This worked for me, in windows XP behind a corporate firewall.
I didnt have to install any local proxy or any other software besides git v1.771 from http://code.google.com/p/msysgit/downloads/list?can=3
$ git config --global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080
$ git config --system http.sslcainfo /bin/curl-ca-bundle.crt
$ git remote add origin https://mygithubuser:mygithubpwd@github.com/repoUser/repoName.git
$ git push origin master
proxyuser= the proxy user I was assigned by our IT dept, in my case it is the same windows user I use to log in to my PC, the Active Directory user
proxypwd= the password of my proxy user
proxy.server.com:8080 = the proxy name and port, I got it from Control Panel, Internet Options, Connections, Lan Settings button, Advanced button inside the Proxy Server section, use the servername and port on the first (http) row.
mygithubuser = the user I use to log in to github.com
mygithubpwd = the password for my github.com user
repoUser = the user owner of the repo
repoName = the name of the repo
If the command line way of configuring your proxy server doesn't work, you can probably just edit .gitconfig (in the root of your profile, which may hide both in C:\Documents and Settings and on some network drive) and add this:
[http]
proxy = http://username:password@proxy.at.your.org:8080
YMMV though, this only covers the first step of the command line configuration. You may have to edit the system git configuration too and I have no idea where they hid that.
In addition of thse answers, I found helpful to consider these 2 points:
One may need to enforce an authentication scheme:
[http]
# https://github.com/git/git/blob/master/Documentation/config.txt
proxyAuthMethod = anyauth|basic|digest|negotiate|ntlm
Also, typically with NTLM authentication schema, one may need to provide explicitely the AD domain.
In git bash:
echo %userdomain%
And update the http.proxy accordingly:
git config --global http.proxy http://DOMAIN\\proxyuser:proxypwd@proxy.server.com:8080
Anyway, investigation may be helped by adding CURL logs:
export GIT_CURL_VERBOSE=1