Create a gist now

Instantly share code, notes, and snippets.

Create a tunnel to github with the git default daemon port like this:

$ ssh

And clone repositories replacing with localhost, like so:

$ git clone git://localhost/someuser/someproject.git

If you want to preserve the “correct” metadata, there are several options

  1. replace localhost origin with after cloning
    git remote rm origin
    git remote add origin git://

  2. add to your hosts file and point it to

  3. add to your ~/.ssh/config:
      HostName localhost

  4. use your favourite packet forwarder, example for Mac OS X:
    sudo ipfw add 00100 fwd,9418 tcp from me to dst-port 9418

    and when you are done, don’t forget to remove it:
    sudo ipfw delete 00100

    (use caution, especially if you are using ipfw already and have rule 00100 in place)

Stuck behind a corporate firewall? Justin Bailey has a good guide. Scroll down for a *nix solution as well.

Git has a config option called ‘core.gitproxy’ which allows you to use a command to tunnel the git:// protocol, which would normally go over TCP port 9418. So in my case, I’ve got a couple off-campus servers that I can use SSH tunnels with. I set up the typical SSH-based SOCKS proxy, thusly (you can also use apps like Shimo to manage tunnels for you):

$ ssh -D 1080 tycho@hostname

NOTE: If you are using ssh shared connection(controlmaster/controlpath), you will have to disable it(forwarding is not yet implemented in shared connection)

$ ssh -S "none" -D 1080 tycho@hostname

Then I use the tools which I’ve made available in this git repository to make cloning with the git:// protocol tunnel through SSH run transparently.

To use the tools, you need to first compile ‘connect.c’ and install the ‘connect’ binary to somewhere in your PATH (/usr/local/bin should work for this). Modify the ‘gitproxy’ script provided in the repository for your configuration (if you use the same command I used above, it should work fine without any editing). Once done editing it, install it as well.

Now tell git about the gitproxy script you just installed:

$ git config --global core.gitproxy gitproxy

Or if you want to use it for a single repository, run the command without ‘—global’ while you’re inside the working tree of the repository.

Or if you want to use it temporarily, use

$ export GIT_PROXY_COMMAND=gitproxy

Once this is all done, you should be able to simply do a git clone without any special URL mangling:

$ git clone git://
Initialized empty Git repository in /Volumes/Development/crisscross/.git/
remote: Counting objects: 1322, done.
remote: Compressing objects: 100% (723/723), done.
remote: Total 1322 (delta 915), reused 874 (delta 586)
Receiving objects: 100% (1322/1322), 566.77 KiB | 60 KiB/s, done.
Resolving deltas: 100% (915/915), done.
nebkor commented Jan 3, 2011

Here's my writeup for getting read-write access via ssh through a firewall:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment