Many corporate firewalls prevent git from using its efficient binary protocol by blocking outbound network connections. Sometimes, you are lucky and are trying to clone a repository that is hosted on a site like github which exports their repositories over HTTP, which would enable you to get through the firewall using the http_proxy environment variable. However, you are usually not that lucky and are only given a git:// URL to clone from.
Fortunately, most corporate firewalls allow for tunneling connections through their HTTP proxies, using HTTP CONNECT. This is normally used for allowing browser to connect to secure websites (using SSL over port 443), but if you are lucky, you can have your firewall administrator configure the proxy to also allow CONNECT for port 9418, which is the port used by git.
Once they have appropriately configured the proxy, you should then be able to use tools like netcat-openbsd or socat to connect through as follows…
- Install
socat. For example, on Debian/Ubuntu, justsudo apt-get install socat. - Create a script called
gitproxyin your bin directory; You will need to replace proxy.yourcompany.com with the name of your proxy host and the port with the port used by the proxy (common ports include 3128, 8123 and 8000). (If the javascript is broken, visit Gist 49288 and download the raw file; or use the original commands as reproduced in the comments.) - Configure
gitto use it:$ git config --global core.gitproxy gitproxy
That’s it! Your git clone commands should now transparently accept git:// URLs.
Update: Fix quoting and add link to Gist 49288.
.
6 Comments
Thanks for your solution, it worked almost perfectly.
The instructions are pretty botched up though: the double quotes should be single, otherwise both ! and $ get interpolated by the shell.
Hopefully wordpress won’t mess this up:
echo ‘#!/bin/sh’ > ~/bin/gitproxy
echo ‘exec socat STDIO PROXY:yourproxy.yourcompany.com:$1:$2,proxyport=3128′ >> ~/bin/gitproxy chmod +x ~/bin/gitproxy
Artem http://beerpla.net http://twitter.com/ArtemR
Thanks for the fix!
I’ve also added a link to a more commented script as a gist on GitHub. That may be easier to download and configure.
Nice idea. However, I’m searching for this solution against an authenticating proxy. Any clues here?
@Sander (sorry for delay; blog wasn’t sending e-mails about pending comments), try appending “,proxyauth=username:password” to the PROXY: command (after the _proxyport).
2009/08/20 15:11:24 socat[12975] E CONNECT git.et.redhat.com:9418: Proxy Error ( The specified Secure Sockets Layer (SSL) port is not allowed. ISA Server is not configured to allow SSL requests from this port. Most Web browsers use port 443 for SSL requests. ) fatal: The remote end hung up unexpectedly
I was trying to clone libvirt. How do i turn off SSL here.
It worked great. Thanks for the info. Should get around to updating git protocol to use $httpproxy or maybe a new $gitproxy variable
6 Trackbacks
Using git over proxy…
I was trying to clone Android repository at office when this problem of “Connection refused” started coming when running the ‘repo’ tool. On subsequent googling, I got this really useful link (thanks to Emil Sit) which explained…
[...] go through a proxy. I had a hard time finding info on how to use git with a proxy, but then I found this link detailing a script that uses socat to get through a proxy. The sample script they provided did half [...]
[...] using tunneling and installing local proxy. Following the instruction from this, this #2, and this #3 link, I installed socat, tconf and proxy+ in my local machine, but got no luck. After doing all the [...]
[...] some further discussions in IRC I was linked on how to use the Git protocol though an HTTP connect proxy, but unfortunately we aren’t running from a proxy in the labs. The next idea was to change the [...]
[...] repos that didn’t have http equivalents I did some searching and found the following website http://www.emilsit.net/blog/archives/how-to-use-the-git-protocol-through-a-http-connect-proxy/ which described how you could use socat to create a tunnel that allowed access to git repositories [...]
[...] started coming when running the ‘repo’ tool. On subsequent googling, I got this really useful link (thanks to Emil Sit) which explained how git can be used over http proxy for those git servers [...]