53

I'm behind a firewall that is blocking port 9418 (git) and am trying to install some tools that are explicitly doing a checkout of git://github.com/..., so I can't switch to https for the checkout.

So I'm wondering if it's possible to redirect all traffic to port 9418 through a proxy and if so how :)

Dharman
  • 30,962
  • 25
  • 85
  • 135

4 Answers4

91

If you are talking about git submodules, try this:

git config --global url.https://github.com/.insteadOf git://github.com/

...taken from here.

This way, you don't need to set any proxy, nor run any script.

mppfiles
  • 2,397
  • 1
  • 21
  • 16
  • This is a super-elegant approach. Worked quite well and didn't involve any crazy proxy nonsense. I'd previously been able to just change the git:// URI but dealing with bundler in deployment made this a real nightmare. Your solution is magically painless. – Greg Combs Apr 09 '13 at 19:13
  • This is the answer that worked for me when a git:// url still didn't work after setting the http.proxy and https.proxy settings. – Chris Matta Jul 09 '13 at 21:16
  • 2
    Also works with ssh: `git config --global url.ssh://git@github.com/.insteadOf git://github.com/` – Lol4t0 Nov 10 '14 at 10:32
  • Works great for git://anongit.gentoo.org/ URLs behind a corporate proxy. Now I can use `layman` for overlays! – Mr. Tao Oct 05 '18 at 10:38
  • 1
    Edited the answer to add another possibility - Github is starting the SSH URL with `git@github.com:` instead of `git://github.com/` now, so you may need to change the end of the command to `git@github.com:`. – LightCC May 30 '19 at 01:38
22

Have a look at core.gitproxy setting in Git config.

Quick googling revealed this script that may be useful (or may not — I did not try it): https://gist.github.com/49288

Alexander Gladysh
  • 39,865
  • 32
  • 103
  • 160
5

You need to make core.gitProxy point to a proxy command that will connect git to the remote server through your SOCKS proxy. You can create a script with the following content to serve as a proxy command:

nc -x <your_proxy_host>:<your_proxy_port> $1 $2

The two parameters, representing the remote host and port, will be passed to the proxy command by git. If you name this script git-proxy and make it accessible from your $PATH, you can call git config to set it:

git config --global --add core.gitProxy git-proxy
Mihai Capotă
  • 2,271
  • 2
  • 32
  • 24
4

Have you tried an ssh-based TCP tunnel? If you have an ssh server that (a) is outside your firewall and (b) allows IP forwarding, you can do:

ssh -L localhost:9418:<remote>:9418 me@remote-ssh-server

or, if you have to run sshd on port 443 to get around your firewall,

ssh -P 443 -L localhost:9418:<remote-host>:9418 me@remote-ssh-server

Then, locally:

git checkout git://localhost/...

Obviously this isn't transparent, and it's a little convoluted - there are no doubt tools out there that are more specifically targetted at the problem. However, I typically use this method because it uses tools I have to hand (ssh and a cheapo virtual server I rent).

(I've actually never tried this with a git connection, but I see no reason why it wouldn't work. I've used it with many other single-TCP-port protocols without problem.)

ijw
  • 4,376
  • 3
  • 25
  • 29
  • Yeah, I can get a checkout on a specific repo working fine, but something out of my control is trying to do `git clone git://github.com/...`, so I can't do a proxy like that since I can't change the URL to `localhost` –  May 02 '11 at 20:08
  • You can try temporarily configuring github.com to be 127.0.0.1 in /etc/hosts – Alexander Gladysh May 02 '11 at 20:09