阅读(3347) (0)

GitHub 复制仓库

2020-08-19 14:37:56 更新

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

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

镜像仓库

  1. 打开 Git Bash。

  1. 创建仓库的裸克隆。

   $ git clone --bare https://github.com/exampleuser/old-repository.git

  1. 镜像推送至新仓库。

   $ cd old-repository.git
   $ git push --mirror https://github.com/exampleuser/new-repository.git

  1. 删除您之前创建的临时本地仓库。

   $ cd ..
   $ rm -rf old-repository.git

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

  1. 打开 Git Bash。

  1. 创建仓库的裸克隆。 将示例用户名替换为拥有仓库的个人或组织的名称,并将示例仓库名称替换为要复制的仓库的名称。

   $ git clone --bare https://github.com/exampleuser/old-repository.git

  1. 导航到刚克隆的仓库。

   $ cd old-repository.git

  1. 拉取仓库的 Git Large File Storage 对象。

   $ git lfs fetch --all

  1. 镜像推送至新仓库。

   $ git push --mirror https://github.com/exampleuser/new-repository.git

  1. 将仓库的 Git Large File Storage 对象推送至镜像。

   $ git lfs push --all https://github.com/exampleuser/new-repository.git

  1. 删除您之前创建的临时本地仓库。

   $ cd ..
   $ rm -rf old-repository.git

镜像其他位置的仓库

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

  1. 打开 Git Bash。

  1. 创建仓库的裸镜像克隆。

   $ git clone --mirror https://github.com/exampleuser/repository-to-mirror.git

  1. 设置到镜像的推送位置。

   $ cd repository-to-mirror.git
   $ git remote set-url --push origin https://github.com/exampleuser/mirrored

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

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