我们经常发布文档更新,此页面的翻译可能仍在进行中。有关最新信息,请访问英文文档。如果此页面上的翻译有问题,请告诉我们

此版本的 GitHub Enterprise 已停止服务 2021-03-02. 即使针对重大安全问题,也不会发布补丁。 要获得更好的性能、改进的安全性和新功能,请升级到 GitHub Enterprise 的最新版本。 如需升级方面的帮助,请联系 GitHub Enterprise 支持

复制仓库

要复制存储库而不对其进行复刻,可以运行特殊克隆命令,然后镜像推送到新仓库。

本文内容

在复制仓库和和推送到仓库的新副本或镜像之前,必须在 您的 GitHub Enterprise Server 实例 上创建新仓库。 在以下示例中,exampleuser/new-repositoryexampleuser/mirrored 是镜像。

镜像仓库

  1. 打开 Terminal(终端)Terminal(终端)Git Bash
  2. 创建仓库的裸克隆。
    $ git clone --bare https://hostname/exampleuser/old-repository.git
  3. 镜像推送至新仓库。
    $ cd old-repository.git
    $ git push --mirror https://hostname/exampleuser/new-repository.git
  4. 删除您之前创建的临时本地仓库。
    $ cd ..
    $ rm -rf old-repository.git

镜像包含 Git Large File Storage 对象的仓库。

  1. 打开 Terminal(终端)Terminal(终端)Git Bash
  2. 创建仓库的裸克隆。 将示例用户名替换为拥有仓库的个人或组织的名称,并将示例仓库名称替换为要复制的仓库的名称。
    $ git clone --bare https://hostname/exampleuser/old-repository.git
  3. 导航到刚克隆的仓库。
    $ cd old-repository.git
  4. 拉取仓库的 Git Large File Storage 对象。
    $ git lfs fetch --all
  5. 镜像推送至新仓库。
    $ git push --mirror https://hostname/exampleuser/new-repository.git
  6. 将仓库的 Git Large File Storage 对象推送至镜像。
    $ git lfs push --all https://github.com/exampleuser/new-repository.git
  7. 删除您之前创建的临时本地仓库。
    $ cd ..
    $ rm -rf old-repository.git

镜像其他位置的仓库

如果要镜像其他位置的仓库,包括从原始位置获取更新,可以克隆镜像并定期推送更改。

  1. 打开 Terminal(终端)Terminal(终端)Git Bash
  2. 创建仓库的裸镜像克隆。
    $ git clone --mirror https://hostname/exampleuser/repository-to-mirror.git
  3. 设置到镜像的推送位置。
    $ cd repository-to-mirror.git
    $ git remote set-url --push origin https://hostname/exampleuser/mirrored

与裸克隆一样,镜像的克隆包括所有远程分支和标记,但每次获取时都会覆盖所有本地引用,因此它始终与原始仓库相同。 设置推送 URL 可简化至镜像的推送。 如需更新镜像,请获取更新和推送。

$ git fetch -p origin
$ git push --mirror