将 git 存储库复制到不同的网络

Copying a git repo to a different network

我项目的 git 存储库当前位于我组织的本地网络上。 该组织要求我将项目的回购移动到不同的本地网络。 我的目标是保留所有提交的历史记录和分支,而不仅仅是将文件复制粘贴到新的 repo。

两个网络上都有一个 GitLab 克隆,如果有帮助的话。

我怎样才能做到这一点?

如有任何帮助,我们将不胜感激。

有几种方法可以将本地存储库移动到新位置:

  1. 使用简单的复制粘贴

这不会对您造成伤害,因为只要您正确复制 .git 文件夹。 Git 如果您将它移到一个新的地方,它不会感到困惑,因为它对项目的位置有一个“相对”的概念。 但是,万一你有 git version 1.7.8 or 1.7.9 并且在你的项目中也有子模块,那么你应该小心使用这种方法,因为它可能会导致问题。阅读更多相关信息 here

  1. 使用git clone --mirror

这是一种更“git”的做事方式。如文档中所述

--mirror

Set up a mirror of the source repository. This implies --bare. Compared to --bare, --mirror not only maps local branches of the source to local branches of the target, it maps all refs (including remote-tracking branches, notes etc.) and sets up a refspec configuration such that all these refs are overwritten by a git remote update in the target repository.

  1. 使用git bundle

这是另一种“git”方式。这将生成一个文件,您可以稍后将其移动到新目的地并在那里应用它。如果在您的情况下,您在新目的地没有仓库,我建议您遵循 answer from VonC 关于使用 git bundle.

移动所有内容

你会想做类似的事情

$ git bundle create /tmp/foo master
$ git bundle create /tmp/foo-all --all
$ git bundle list-heads /tmp/foo
$ git bundle list-heads /tmp/foo-all

如果您可以轻松访问新位置,我认为最简单的方法就是复制粘贴您的项目。