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).
# 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:
# 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:
# 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:
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…
“You have died of linkrot.”
Okay, not really, but your link to connect.c is dead.
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!
thank you for this. you are a champion.
Just wanna add something here. Need a fast and clean proxy? Try proxy.my
Unblock friendster, facebook, myspace and even youtube!
Awesome ! Many thanks.
Awesome… Some git repos will access fine through http so I can use my work http proxy, but this is great for the ones that don’t respond nicely to http paths.
This is great. TKS
[...] to ThreeBytesFull, from which I re-adapted the scripts to work on [...]
whenever i execute
repo init -u git://android.git.kernel.org/platform/manifest.git
i get following error please help me
Getting repo …
from git://android.git.kernel.org/tools/repo.git
FATAL: failed to begin relaying via HTTP.
fatal: The remote end hung up unexpectedly
Ensure that your GIT_SSH and GIT_PROXY_COMMAND environment variables are set as described above. The repository URL you’re using isn’t HTTP so I’m not sure where the HTTP errors are coming from. Is that the current version of the repo script from http://source.android.com/download/using-repo?
http error is from the connect script
whenever i execute
repo init -u git://android.git.kernel.org/platform/manifest.git
i get error
FATAL: Connection closed by peer.
fatal: The remote end hung up unexpectedly
if i use socks-gw as above
if i change socks-gw to
/path/to/connect -H my.socks.server:1080 $@
i get following error
Getting repo …
from git://android.git.kernel.org/tools/repo.git
FATAL: failed to begin relaying via HTTP.
fatal: The remote end hung up unexpectedly
Thanks
suma
[...] http://threebytesfull.com/2008/04/git-with-and-without-proxy/ a few seconds ago from api [...]
Hi,
If I only have a http proxy, for instance, 172.22.22.22:8080 How can I use your script to download a git repository? I need the connec -S or -H parameter? I’m trying to clone a repository without http access: git clone git://gitorious.org/vjaquez-beagleboard/marmita.git