Git clone from remote ssh repository - 在执行 clone 命令之前更改远程网络上的机器 [英] Git clone from remote ssh repository - change the machine on the remote network before executing the clone command

查看:15
本文介绍了Git clone from remote ssh repository - 在执行 clone 命令之前更改远程网络上的机器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个 git 存储库从我公司的服务器克隆到我的个人计算机.从外部"访问这些服务器的唯一方法是通过 ssh 登录到machine1"

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 user@machine1.company.xy

不幸的是,该特定机器上并未安装 git.所以像

Unfortunately, git ist not installed on that specific machine. So a git clone like

git clone ssh://user@machine1.company.xy/path/to/repo <local-repo-path>

行不通.我必须做的是在通过machine1"登录网络后更改为另一台安装了 git 的机器machine2".所以为了让克隆工作,我必须执行像

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

在实际执行 git 命令之前.有没有办法做到这一点?可能是预克隆钩子之类的东西?

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?

期待您的提示和建议!

推荐答案

您可以通过配置 ssh 代理命令来完成此操作.注意:这里假设 netcat 在代理服务器上可用;如果需要,您可以使用 perl 中的类似脚本或任何其他脚本替换 netcat.

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.

将以下内容添加到您的 ~/.ssh/config,根据需要创建:

Add the following to your ~/.ssh/config, creating it if needed:

Host machine1
User yourusername
HostName machine1.yourcompany.com

Host machine2
User yourusername
ProxyCommand ssh machine1 nc %h %p
HostName machine2.internal.network

现在你可以ssh machine2,它会自动通过machine1隧道.这意味着使用 git 就像 git clone ssh://machine2/path 一样简单.

Now you can ssh machine2 and it will automatically tunnel through machine1. This means using git is as simple as git clone ssh://machine2/path.

也可以使用 git bundle 命令.不过,对于适当的 ssh 代理设置,这应该不是必需的.

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.

这篇关于Git clone from remote ssh repository - 在执行 clone 命令之前更改远程网络上的机器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆