7

I am trying to use ssh port forwarding to defeat corporate firewall:

ssh git@GIT_SERVER -L9418:GIT_SERVER:9418

and in another terminal I run

git clone git://localhost:repositories/project.git

But I get the following error:

Initialized empty Git repository in /Users/aboxer/tmp/glucosia/.git/

fatal: Unable to look up localhost (port repositories) (nodename nor servname provided, or not known)

Thanks!

Cascabel
  • 422,485
  • 65
  • 357
  • 307
Jacko
  • 11,326
  • 15
  • 66
  • 112
  • This is more appropriate for serverfault. – Ikke Mar 28 '10 at 14:34
  • 1
    @Ikke: In fact, the answer (I believe) is wholly to do with the git url syntax, and stackoverflow has been well-established as the place for questions about how to use git. – Cascabel Mar 28 '10 at 14:38
  • I realized it afterwards. I thought it was about how to set up the firewall. – Ikke Mar 28 '10 at 18:55

4 Answers4

7

I'm pretty sure your problem (or at least the one causing this particular error) is here:

git clone git://localhost:repositories/project.git

If you look at the list of url notations in man git push you'll see the relevant example:

git://host.xz[:port]/path/to/repo.git/

With the colon, you're using "repositories" as the port name, and git (understandably) has trouble connecting to port repositories on local host! What you're looking for is:

git://localhost/path/to/repositories/project.git

or perhaps

git://localhost/~user/repositories/project.git

Edit:

I probably should've said this from the start, but I can't actually think of a reason you'd need to use SSH tunneling with git. Its default transport protocol is ssh; the git protocol is really only present to allow public repositories to be fetched from without an account. If you can SSH into the machine where the repository is located, you can just fetch via ssh:

git clone ssh://[user@]host.xz/path/to/repo.git
git clone ssh://[user@]host.xz/~/path/to/repo.git
git clone ssh://[user@]host.xz/~user/path/to/repo.git
Cascabel
  • 422,485
  • 65
  • 357
  • 307
  • yeah, the funny thing is that when I am not behind the firewall, the command git clone git://GIT_SERVER:repositories/project.git works fine, but git clone git://GIT_SERVER/repositories/project.git does not – Jacko Mar 28 '10 at 17:21
  • @Jacko: I take it that you mean that removing the colon here doesn't help? Also, is there any reason you can't simply use `git clone ssh://GIT_SERVER/path/to/repositories/project.git`? Git's default transport protocol is ssh... – Cascabel Mar 28 '10 at 17:29
  • Thanks, Jefromi. Fetching via ssh as described in your edit works fine. – Jacko Mar 28 '10 at 19:03
  • legend, wait for it... dary. – Louis Nov 29 '12 at 02:33
  • ssh tunneling is necessary to get past firewalls, right? Example, if the git repo is on a server that I can't reach "normally" but, rather, can only ssh to, then don't I need to tunnel to access git on that server? (This is the problem I'm currently having.) – Olie Nov 14 '13 at 23:52
  • @Olie The last paragraph addresses this. You don't ever really need to use ssh tunneling with git. If you can get through with ssh, you can just access the repo directly via ssh (using the url syntax I mentioned there), rather than jumping through the hoops of tunneling another protocol through ssh. And if you can't get through with ssh, you can't use ssh tunneling. – Cascabel Nov 15 '13 at 07:52
  • @Jefromi unfortunately that's not true. If A is behind a firewall, and you need to tunnel through B to ssh to A, then you can not git right into A. Suppose I have a VNC session on A. I can't connect unless I first establish a tunnel through B. Without the tunnel, my local machine can't even see A. I'm trying to work out this exact issue right now. There is no web server on A, so I can't use https. Git clone implicitly looks for port 22 (ssh). So if I tunnel `ssh -L 7000:A:22 user@B`. Then I can't just git to `localhost:`. I need to somehow specify the port. – abalter Feb 03 '16 at 05:50
6

I wrote a complete response/guide here: http://vladzloteanu.wordpress.com/2010/12/18/git-through-ssh-port-forwarding-ssh-tunneling/.

Vlad Zloteanu
  • 8,363
  • 3
  • 38
  • 58
1

The short version of Vlad Zloteanu's answer:

Set up the tunnel:

ssh ServerWithSSHAccessAddress -L 2000:GitServerAddress:22 -N , &

Clone the repo

git clone ssh://user@localhost:2000/my_repo.git
Pylinux
  • 9,386
  • 3
  • 52
  • 62
0

Here are the steps that worked for me. My system is behind company firewall and it is domain joined:

  • First npm needs to be installed
  • Fiddler needs to be in running mode as well. Fiddler needs to be running with ‘Automatically Authenticate’ option under ‘Rules’ enabled
  • Install Git via command:

npm install git

  • Update protocol from git to https:

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

lucas
  • 3,457
  • 6
  • 23
  • 42