7

I'd like to clone a git repository from my company's servers to my personal computer. The only way to acces these servers from "outside" is by logging in per ssh to 'machine1'

ssh user@machine1.company.xy

Unfortunately, git ist not installed on that specific machine. So a git clone like

git clone ssh://user@machine1.company.xy/path/to/repo <local-repo-path>

won't work. What I would have to do is to change to another machine 'machine2' where git is installed after having logged in to the network via 'machine1'. So to get the clone working I would have to execute a command like

ssh machine2

before actually executing the git command. Is there any way to do that? Something like a pre-clone hook maybe?

Is it possible to somehow pack the remote repository into a file (patch?), to copy that file onto the local machine and to clone from that file?

Looking forward to your hints and suggestions!

bdonlan
  • 224,562
  • 31
  • 268
  • 324
Deve
  • 4,528
  • 2
  • 24
  • 27

1 Answers1

13

You can do this by configuring a ssh proxy command. Note: this assumes netcat is available on the proxy server; you can replace netcat with a similar script in perl or whatever if needed.

Add the following to your ~/.ssh/config, creating it if needed:

Host machine1
User yourusername
HostName machine1.yourcompany.com

Host machine2
User yourusername
ProxyCommand ssh machine1 nc %h %p
HostName machine2.internal.network

Now you can ssh machine2 and it will automatically tunnel through machine1. This means using git is as simple as git clone ssh://machine2/path.

It is also possible to bundle the repository into a single file, using the git bundle command. This shouldn't be necessary with a proper ssh proxy setup though.

bdonlan
  • 224,562
  • 31
  • 268
  • 324
  • This sounds like a great solution. Unfortunately, netcat obviously doesn't exit on the remote machine. It's a sparc architecture running SunOS 10. Is there an alternative to netcat I could possibly use? – Deve Jan 22 '11 at 20:30
  • 1
    The only requirement is you put together some simple program that'll relay from stdin/stdout to some arbitrary remote host; you can probably throw together some simple script in whatever scripting languages are available there, or compile netcat or socat or something and put them in your home directory – bdonlan Jan 23 '11 at 03:08
  • Okay, I see what you mean. Seems like a challenge to me, but I'll try my best. Thanks again! – Deve Jan 23 '11 at 19:11