How to use SSH tunnel to forward git protocol? [cl

2019-02-15 18:53发布

问题:

I know similar questions have been asked many times. But all I can find are answers about how to setup proxy for http or ssh protocols. Here is the situation. For some reason, the git repository on gitorious I need to clone doesn't allow http or ssh. When I use "git clone http://gitorious.org/...." I got ".../refs not found: did you run git update-server-info on the server?" error. If I use "git clone ssh://git@gitorious.org/...", I got "fatal: The remote end hung up unexpectedly" error. (probably I should blame android "repo" for this one, because I can do git clone directly, but not through "repo sync"). (The above tests are all done without firewall.)

So my question is how to setup SSH tunnel to use git protocol behind a firewall. Specifically, I need to do "git clone git://gitorious.org/..." (not ssh://, not http://) behind firewall. Thanks!

回答1:

The git:// protocol operates on port 9418 (documented in the git-daemon man page, or run git daemon --help). To forward this via an SSH tunnel, you would do something like this:

ssh -L 9418:gitorious.org:9418 your.remote.host

Once connected, you would clone a remote repository like this:

git clone git://localhost/path/to/repository.git

In order for this to work you obviously need a machine outside your firewall to be the target of the ssh command.



标签: git proxy