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

16,626

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.

Share:
16,626

Related videos on Youtube

Deve
Author by

Deve

Updated on May 17, 2022

Comments

  • Deve
    Deve about 2 years

    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!

  • bdonlan
    bdonlan over 13 years
    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
  • Deve
    Deve over 13 years
    Okay, I see what you mean. Seems like a challenge to me, but I'll try my best. Thanks again!