git 从防火墙后面的机器克隆到远程机器

发布于 2024-11-02 12:20:28 字数 800 浏览 0 评论 0原文

我可以从我的工作机器 ssh 到我的家庭机器

这有效

Work$> ssh -x -Y [电子邮件受保护]

现在如果我想要将工作机器上的 git 存储库克隆到我的家庭机器上。我发出命令

Work$> git clone ~/my_new_work_git_repo [email protected]:/home/myname

但这最终会创建一个名为“[email protected]",在我的工作计算机上有子目录“home”,然后是“myname”。无论我尝试什么 URL 方案 ssh:// 或 rsync://

我做错了什么,存储库都会克隆到我的本地工作计算机上这个愚蠢的命名目录。我通读了几个似乎相关的问题,但无法弄清楚为什么会失败

I can ssh from my work machine to my home machine

This works

Work$> ssh -x -Y [email protected]

Now if I want to clone a git repo on my work machine to my home machine . I issue the command

Work$> git clone ~/my_new_work_git_repo [email protected]:/home/myname

But this ends up creating a directory named "[email protected]" with subdirectories "home" and then "myname" on mY work machine . The repo gets clones to this silly named directory on my local Work machine no matter what URL scheme I try ssh:// or rsync://

What am I doing wrong. I read through several of the questions that seemed related but cannot figure out why this fails

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

能怎样 2024-11-09 12:20:28

从您的问题中很难判断您要尝试克隆的方向。

如果您的存储库位于家庭计算机上,并且您试图将其克隆到工作计算机上,则参数顺序会向后。它是 gitcloneoriginalclone,所以在你的情况下:

git clone [email protected]:/home/myname ~/my_new_work_git_repo

如果你的意思是你正在尝试克隆一个正在工作的存储库,这样你就可以将它放在你的家庭机器上,那么你将需要能够在另一个方向上进行 SSH;从您的家用机器到您的工作机器。您无法通过 SSH“推送”克隆,只能“拉取”(也就是说,您只能从本地或远程存储库在本地计算机上创建克隆)。

如果您需要将存储库从工作计算机获取到家庭计算机,但无法从家庭计算机通过 SSH 连接,则只需克隆到新的裸存储库,然后 scp 将其发送到您的计算机家用机。现在,当您在家时,您可以克隆该裸存储库、使用它、推送到它等等。当你在工作时,你可以从中拉出、推动等等。

以下是其工作原理的示例:

Work
gt; git clone --bare ~/my_work_repo repo.git
Work
gt; scp -r repo.git [email protected]:/home/myname
Work
gt; git remote add home [email protected]:/home/myname/repo.git

Home
gt; git clone repo.git my_home_repo
Home
gt; cd my_home_repo
Home
gt; # edit, commit, etc
Home
gt; git push origin

Work
gt; git remote update
Work
gt; git pull home master

It's a bit hard to tell from your question which direction you are trying to clone in.

If your repository is on your home machine, and you are trying to clone it onto your work machine, then you have the argument order backwards. It's git clone original clone, so in your case:

git clone [email protected]:/home/myname ~/my_new_work_git_repo

If you mean that you are trying to clone a repository that is at work, so you can have it on you home machine, then you will need to be able to SSH in the other direction; from your home machine, to your work machine. You cannot "push" a clone over SSH, you can only "pull" (that is, you can only create the clone on the local machine, either from a local or remote repo).

If you need to get the repo from your work machine to your home machine, but can't SSH in from your home machine, you can just clone into a new bare repository, and then scp it to your home machine. Now when you're at home, you can clone that bare repository, work with it, push to it and so on. When you're at work, you can pull from it, push to it, and so on.

Here's an example of how this would work:

Work
gt; git clone --bare ~/my_work_repo repo.git
Work
gt; scp -r repo.git [email protected]:/home/myname
Work
gt; git remote add home [email protected]:/home/myname/repo.git

Home
gt; git clone repo.git my_home_repo
Home
gt; cd my_home_repo
Home
gt; # edit, commit, etc
Home
gt; git push origin

Work
gt; git remote update
Work
gt; git pull home master
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文