Git with and without proxy

I use Git both at home and at work; at home I’ve got a direct connection but at work I must connect through a SOCKS proxy for external access.

Although Git supports proxy configuration, it’s irritating to have to change this all the time depending on my location. Setting the environment variable GIT_PROXY_COMMAND overrides whatever proxy configuration already exists - this is all we need to get git:// repositories to work. To get Git-over-SSH connections to work, which you probably want for push operations, you’ll also need to set up GIT_SSH.

I’ve created some simple shell scripts to help. The first is a simple wrapper for connect.c (which you may need to compile, of course).

#!/bin/sh
# Filename: ~/bin/socks-gw
# This script connects to a SOCKS proxy using connect.c
/path/to/connect -S my.socks.server:1080 $@

The second is another simple wrapper for SSH through a SOCKS proxy:

#!/bin/sh
# Filename: ~/bin/socks-ssh
# This script opens an SSH connection through a SOCKS server
ssh -o ProxyCommand="${HOME}/bin/socks-gw %h %p" $@

Lastly, I have a script I source when at work to set the environment variables for me:

#!/bin/sh
# Filename: ~/bin/work
# This script sets Git to use the SOCKS proxy
export GIT_SSH="${HOME}/bin/socks-ssh"
export GIT_PROXY_COMMAND="${HOME}/bin/socks-gw"

And I’ve put an alias in my .bash_profile to help me remember to source it instead of running it:

alias work="source ${HOME}/bin/work"

Now when I use Git at home, it just works without having to remove any proxy config, and when I use it at work I just type work in my shell and it works there too…

5 Responses to “Git with and without proxy”

  1. Jonathan Quimbly says:

    “You have died of linkrot.”

    Okay, not really, but your link to connect.c is dead.

  2. admin says:

    Hmm, looks as though there’s some kind of configuration error at the other end. Links updated to point to the file directly in the meantime.

    Thanks!

  3. james says:

    thank you for this. you are a champion.

  4. Proxy says:

    Just wanna add something here. Need a fast and clean proxy? Try proxy.my

    Unblock friendster, facebook, myspace and even youtube!

  5. Ludovic Kuty says:

    Awesome ! Many thanks.

Leave a Reply