Using git behind a proxy

This is a simple recipe about how to use git behind a proxy.

Right now I’m working behind a very restrictive firewall and I can’t get any port I need open, so I use a proxy socks for working with git,bzr,jabber and so on. I was looking for an easy way to use git with a proxy but I didn’t find easily the solution. After some researches a friend (Roberto) found the solution and we use it at work.

Let’s see it 😉

Just in case we don’t have it:

$ mkdir ~/bin

Now the interesting part, the wrapper for the proxy:

$ cat <<EOF>> ~/bin/proxy-wrapper
#!/bin/sh
# Put your own values
PROXY_IP=10.0.0.80
PROXY_PORT=22000

nc -x${PROXY_IP}:${PROXY_PORT} -X5 $*

EOF
$ chmod +x ~/bin/proxy-wrapper

Note that you’ll need to have installed netcat (the openbsd’s one: netcat-openbsd) to be able to use the command nc with the option -x.

Then you’ll have to be sure you have setted the ~/bin directory on your PATH and then add the env variable GIT_PROXY_COMMAND. That variable will be used by git for doing pushes through git or ssh protocol:

$ cat <<EOF>> ~/.bashrc
export PATH=~/bin:"${PATH}"
export GIT_PROXY_COMMAND=~/bin/proxy-wrapper
EOF

Now you will be able to use git normally with no worries about the firewall, nat or whatever.

Creative Commons Attribution-ShareAlike 3.0 España
This work by Juanje Ojeda is licensed under a Creative Commons Attribution-ShareAlike 3.0 España.