从远程 ssh 存储库进行 Git 克隆 - 在执行克隆命令之前更改远程网络上的机器
我想将 git 存储库从我公司的服务器克隆到我的个人计算机。从“外部”访问这些服务器的唯一方法是通过 ssh 登录到“machine1”。
ssh [email protected]
不幸的是,git 没有安装在该特定机器上。所以像这样的 git 克隆
git clone ssh://[email protected]/path/to/repo <local-repo-path>
是行不通的。我要做的就是在通过“machine1”登录网络后更改为另一台安装了 git 的机器“machine2”。因此,为了让克隆工作,我必须像
ssh machine2
实际执行 git 命令之前一样执行命令。有什么办法可以做到这一点吗?也许是像预克隆钩子之类的东西?
是否可以以某种方式将远程存储库打包到文件(补丁?)中,将该文件复制到本地计算机上并从该文件克隆?
期待您的提示和建议!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过配置 ssh 代理命令来完成此操作。注意:这假设 netcat 在代理服务器上可用;如果需要的话,你可以用 perl 中的类似脚本替换 netcat 或其他脚本。
将以下内容添加到您的
~/.ssh/config
中,并根据需要进行创建:现在您可以
ssh machine2
,它将自动通过 machine1 建立隧道。这意味着使用 git 就像 git clone ssh://machine2/path 一样简单。还可以使用
将存储库捆绑到单个文件中git bundle
命令。不过,对于正确的 ssh 代理设置来说,这并不是必需的。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:Now you can
ssh machine2
and it will automatically tunnel through machine1. This means using git is as simple asgit 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.