Larry Ewing's Penguin Two Penguins Larry Ewing's Penguin

Using GIT through a SOCKS proxy

Step One Create a wrapper script for netcat

First you need netcat (a utility named nc). It's probably already on your system. The version in F9 just works.

Git needs a command that it can just pass a host and port to, but nc takes a few more arguments, so you need to make a wrapper script. You could put it in /usr/bin or your own /home/user/bin directory or something. Do this:

cat > /somepath/bin/proxy-wrapper
nc -xproxy:1080 -X5 $*
Then hit Ctrl-D to save the file. This assumes you're using a SOCKS version 5 proxy server named "proxy".

Note If you're on Ubuntu, your version of netcat probably doesn't support the -x and -X flags. You can update it to the version that does work, like this:

$ sudo apt-get install netcat-openbsd

Step Two Make your script executable

$ chmod +x /somepath/bin/proxy-wrapper

Step Three Set the git proxy environment variable

Either temporarily for this session, or permanently in your ~/.bashrc, do:

$ export GIT_PROXY_COMMAND="/somepath/bin/proxy-wrapper"
If you also need to access local git servers behind your proxy server, you don't want this to be set permanently.

Step Four Profit

Now you should be able to get to git trees using git:// protocol (port 9418) through your proxy.

$ git clone git://

Step Five Add some aliases to your .bashrc

$ cat >> ~/.bashrc

alias git-proxy-local='export -n GIT_PROXY_COMMAND'
alias git-proxy-remote='export GIT_PROXY_COMMAND="/somepath/bin/proxy-wrapper"'
Or if you're like me, less is more and you might use 'gpl' and 'gpr' instead.

Then, hit Ctrl-D to save. Then read in the new aliases:

$ . ~/.bashrc

Step Six Profit further

Now you should be able to type git-proxy-local when you are about to access a local git tree on your intranet, and git-proxy-remote when you need to access a remote git tree through the proxy.

Back to Linux Tips

Last modified: March 12, 2010, 2:41pm

Valid HTML 4.01!

solvency amendment