Git with and without proxy

| | Comments (0) | TrackBacks (1)

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…

1 TrackBacks

Listed below are links to blogs that reference this entry: Git with and without proxy.

TrackBack URL for this entry: http://threebytesfull.com/mt/mt-tb.cgi/4

Git via Tor from Simply Sam on June 20, 2008 8:54 AM

Recently (or rather, like every summer), my ISP started having an array of issues (including, but not limited to: bottlenecks in their main routers, looping routes, broken routes) that are starting to get worse by the day, so bad, that two days ago was... Read More

Leave a comment