【问题标题】:How do I clone my git reposity to a remote machine?如何将我的 git 存储库克隆到远程计算机?
【发布时间】:2015-06-19 21:10:51
【问题描述】:

我在我的电脑上设置了一个 git repo。我还有一台可以通过 ssh 进入的远程机器。我想将 repo 克隆到远程机器(然后让它们与推拉同步)。我该怎么做呢?我只从 GitHub 克隆过。

【问题讨论】:

  • 你能从远程机器访问你的计算机吗(所以首先ssh 访问远程计算机,然后ssh 回到你的计算机)?
  • 嗯,不,这就是问题所在(我认为),我不知道我机器的地址。当我输入hostname 时,我只得到username.local,我无法使用。
  • 使用ifconfig 查找您的IP

标签: git


【解决方案1】:

1) 在远程机器上初始化bare git 仓库。

ssh remote_machine
mkdir my_project
cd my_project
git init --bare
git update-server-info # If planning to serve via HTTP

2) 将本地仓库配置为能够从远程仓库拉取/推送。

git remote add origin git@remote_machine:my_project.git
git push -u origin master

现在两台机器都同步了。

【讨论】:

  • 为什么不把git clone 作为第一步呢?
  • 这是其中一种方法
  • 我试过这个,但得到一个远程源已经存在的错误。我认为这是因为我最初是从远程机器克隆存储库的?
  • 可能。只需以其他名称添加远程机器。 git remote add upstream git@remote_machine:my_project.gitgit push -u upstream master
  • 不起作用。 “my_project”将在其中包含 git 文件,而本地计算机将在“.git”文件夹中包含这些文件。然后我尝试cd my_project; git init --bare .git。现在我得到了我期望的 git 文件。所以我遵循你的第 2 部分步骤。然后我去远程输入git status,我得到fatal: This operation must be run in a work tree
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-11
  • 1970-01-01
  • 1970-01-01
  • 2013-06-24
  • 1970-01-01
  • 2014-10-11
相关资源
最近更新 更多