Git可以通过SSH端口转发工作吗?

11

我的情况是,我可以通过ssh访问放置有git存储库的ComputerB(代码库),但是我的本地连接速度太慢了,无法克隆代码。我可以访问另一台更快的机器(ComputerA),因此我想通过ComputerA来克隆代码。

这是我所做的:

           ssh tunnel                           ssh tunnel
MyComputer ----------> ComputerA (I can ssh to) ----------> ComputerB (where the Code repos is and I can ssh to but too slow)

使用类似这样的命令:

ssh -L1234:ComputerA_ip:22 Code_repos_ip

那么:

git clone git+ssh//localhost/repos local_repos (how can I assign the port 1234?)

如果这不起作用,我还能做什么?


我在这里写了一个完整的响应/指南:http://vladzloteanu.wordpress.com/2010/12/18/git-through-ssh-port-forwarding-ssh-tunneling/. - Vlad Zloteanu
4个回答

15

通过两个连接会使你的连接速度更快吗?

无论如何,你应该能够做到:

git clone git+ssh://localhost:1234/repos local_repos

9
此外,您可以尝试在~/.ssh/config中添加端口号:
Host ComputerA
HostName localhost
Port 1234

然后在使用git clone命令时,使用ComputerA:

git clone git+ssh://ComputerA/repos local_repos

在我的情况下 <br> yubaofu@~ cat .ssh/config 主机 github.com 主机名 localhost 端口 7070 yubaofu@~ git clone git+ssh://github.com/fuyou001/yubao-studying.git 正在克隆 'yubao-studying'...<br> 无法工作 - fuyou001

1

查看SSH的命令文件。您可以在通过SSH登录时自动执行命令。这在authorized_keys文件中指定。因此,在计算机A上,您将拥有一个命令文件,该文件会自动SSH到计算机B。然后当您连接到计算机A时,它会自动连接到计算机B。对于您的计算机而言,它直接连接到计算机B。您甚至可以使用压缩隧道。


-3

首先将代码克隆到电脑A,然后再从电脑A克隆到电脑B。不过,您需要通过ssh登录电脑A以便拉取新的内容。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接