Use ssh -R to "reverse clone" a git repo
Contents
One can use ssh -R
to open a reverse tunnel from a remote back to your local machine, allowing one to use git to clone from your local machine to the remote server.
One feature/drawback of git is that git clone
is a pull-only operation: it must be able to see a remote to clone it. This is fine in 99% of use cases, but sometimes, one wishes it were possible to “push clone” a new repository, e.g. from a laptop to a server.
However, by using the reverse tunneling feature of ssh, we can achieve this behaviour in a round-about way.
Specifically:
|
|
Notes:
- Your laptop (or the client end of the original ssh connection) must be running sshd, and you must be able to log in (just run
ssh ${laptop_username}@localhost
on your laptop to check). If not, enable it. - You may need to adjust the port (22222) if there is already something running on this port on the server. You should see ssh complain if that’s the case.
- If you’re using this primarily as a backup of the local git repository, you’ll probably want to investigate the
receive.denyCurrentBranch
git config option. Specifically, you’ll probably want to set it toupdateInstead
, and read the info on push hooks in the git docs.
Author K.D. Murray
LastMod 2022-04-05