需要在防火墙后面使用git:尝试ssh隧道

Jac*_*cko 7 git ssh portforwarding tunnel

我试图使用ssh端口转发来打败企业防火墙:

ssh git@GIT_SERVER -L9418:GIT_SERVER:9418
Run Code Online (Sandbox Code Playgroud)

在另一个终端我跑

git clone git://localhost:repositories/project.git
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

/Users/aboxer/tmp/glucosia/.git/中初始化的空Git存储库

致命:无法查找localhost(端口存储库)(提供节点名称或服务名称,或未知)

谢谢!

Cas*_*bel 7

我很确定你的问题(或至少导致这个特殊错误的问题)在这里:

git clone git://localhost:repositories/project.git
Run Code Online (Sandbox Code Playgroud)

如果你查看man git push 中的url符号列表,你会看到相关的例子:

git://host.xz[:port]/path/to/repo.git/
Run Code Online (Sandbox Code Playgroud)

使用冒号,您使用"存储库"作为端口名称,并且git(可以理解)无法连接到本地主机上的端口存储库!你在寻找的是:

git://localhost/path/to/repositories/project.git
Run Code Online (Sandbox Code Playgroud)

也许

git://localhost/~user/repositories/project.git
Run Code Online (Sandbox Code Playgroud)

编辑:

我可能应该从一开始就说过这个,但我实际上无法想到你需要在git中使用SSH隧道的原因.它的默认传输协议是ssh; git协议实际上只是为了允许在没有帐户的情况下从中获取公共存储库.如果您可以SSH到存储库所在的机器,您只需通过ssh获取:

git clone ssh://[user@]host.xz/path/to/repo.git
git clone ssh://[user@]host.xz/~/path/to/repo.git
git clone ssh://[user@]host.xz/~user/path/to/repo.git
Run Code Online (Sandbox Code Playgroud)