If you have to use git from behind a firewall you may have encountered problems using the default git protocol to communicate with remote repositories. The git protocol usies port 9418 which is not normally open on corporate network setups. Sometimes however, you can use a SOCKS proxy which permits forwarding connections at the tcp level. Or you can arrange to tunnel connections over SSH using SOCKS on the client end.

OpenSSH has a -D option which enables dynamic tunnels. What this means it that your SSH session can act as a SOCKS4 or SOCKS5 proxy, accepting connection requests on a local port and actually making the connection from the remote machine.

So how do we make use of this with Git? Git permits the user to define a proxy command using either variables in the config file or with an override via an environment variable. So setting GIT_PROXY_COMMAND to some command that will use the SOCKS proxy will enable proxying git. I use the connect program to do this. I've previously used this with SSH to use http proxies but it also supports SOCKS. We need a script that will take two arguments, the host and port, and make a network connection over socks.

connect -s $*
will have connect read the SOCKS_SERVER environment variable for the proxy address (eg: export SOCKS_SERVER=localhost:1080). Given this script we can now set
and git will begin tunnelling over the SOCKS proxy.

This method works with Windows using msysGit as well. However, on windows it is more troublesome to use a script like this so instead I build a version of the connect program with the default option set to -s and called it socks_connect.exe. Otherwise nearly everything works the same using plink or putty for the SSH connection and enabling a dynamic tunnel on the putty configuration page.