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 configurations, 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 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…
Leave a comment