Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git clone from remote ssh repository - change the machine on the remote network before executing the clone command

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 [email protected]

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

git clone ssh://[email protected]/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!

like image 371
Deve Avatar asked Jan 22 '11 19:01

Deve


1 Answers

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.

like image 169
bdonlan Avatar answered Sep 20 '22 19:09

bdonlan