{"meta":{"title":"复制一个仓库","intro":"要维护存储库的镜像而不对其进行复刻，可以运行特殊的克隆命令，然后镜像推送到新存储库。","product":"存储库","breadcrumbs":[{"href":"/zh/repositories","title":"存储库"},{"href":"/zh/repositories/creating-and-managing-repositories","title":"创建和管理存储库"},{"href":"/zh/repositories/creating-and-managing-repositories/duplicating-a-repository","title":"复制一个仓库"}],"documentType":"article"},"body":"# 复制一个仓库\n\n要维护存储库的镜像而不对其进行复刻，可以运行特殊的克隆命令，然后镜像推送到新存储库。\n\n> \\[!NOTE]\n> 如果你在另一个基于 Git 的托管服务上托管了项目，则可以使用 GitHub 工具自动将项目导入到 GitHub Importer。 有关详细信息，请参阅“[关于 GitHub 导入工具](/zh/migrations/importing-source-code/using-github-importer/about-github-importer)”。\n\n在将原始存储库推送到存储库的新副本或镜像之前，必须在 GitHub.com 上\\_创建新的存储库\\_。 在这些示例中，`exampleuser/new-repository` 或 `exampleuser/mirrored` 为镜像。\n\n## 镜像仓库\n\n1. 打开<span class=\"platform-mac\">终端</span><span class=\"platform-linux\">终端</span><span class=\"platform-windows\">Git Bash</span>。\n\n2. 创建仓库的裸克隆。\n\n   ```shell\n   git clone --bare https://github.com/EXAMPLE-USER/OLD-REPOSITORY.git\n   ```\n\n3. 镜像推送至新仓库。\n\n   ```shell\n   cd OLD-REPOSITORY\n   git push --mirror https://github.com/EXAMPLE-USER/NEW-REPOSITORY.git\n   ```\n\n4. 删除您之前创建的临时本地仓库。\n\n   ```shell\n   cd ..\n   rm -rf OLD-REPOSITORY\n   ```\n\n## 同步包含 Git 大型文件存储 对象的仓库。\n\n1. 打开<span class=\"platform-mac\">终端</span><span class=\"platform-linux\">终端</span><span class=\"platform-windows\">Git Bash</span>。\n\n2. 创建仓库的裸克隆。 将示例用户名替换为拥有仓库的个人或组织的名称，并将示例仓库名称替换为要复制的仓库的名称。\n\n   ```shell\n   git clone --bare https://github.com/EXAMPLE-USER/OLD-REPOSITORY.git\n   ```\n\n3. 导航到刚克隆的仓库。\n\n   ```shell\n   cd OLD-REPOSITORY\n   ```\n\n4. 拉取仓库的 Git 大型文件存储 对象。\n\n   ```shell\n   git lfs fetch --all\n   ```\n\n5. 镜像推送至新仓库。\n\n   ```shell\n   git push --mirror https://github.com/EXAMPLE-USER/NEW-REPOSITORY.git\n   ```\n\n6. 将仓库的 Git 大型文件存储 对象推送至镜像。\n\n   ```shell\n   git lfs push --all https://github.com/EXAMPLE-USER/NEW-REPOSITORY.git\n   ```\n\n7. 删除您之前创建的临时本地仓库。\n\n   ```shell\n   cd ..\n   rm -rf OLD-REPOSITORY\n   ```\n\n## 镜像其他位置的仓库\n\n如果要镜像其他位置的仓库，包括从原始位置获取更新，可以克隆镜像并定期推送更改。\n\n1. 打开<span class=\"platform-mac\">终端</span><span class=\"platform-linux\">终端</span><span class=\"platform-windows\">Git Bash</span>。\n\n2. 创建仓库的裸镜像克隆。\n\n   ```shell\n   git clone --mirror https://github.com/EXAMPLE-USER/REPOSITORY-TO-MIRROR.git\n   ```\n\n3. 设置到镜像的推送位置。\n\n   ```shell\n   cd REPOSITORY-TO-MIRROR\n   git remote set-url --push origin https://github.com/EXAMPLE-USER/MIRRORED\n   ```\n\n   与裸克隆一样，镜像的克隆包括所有远程分支和标记，但每次获取时都会覆盖所有本地引用，因此它始终与原始仓库相同。 设置推送 URL 可简化至镜像的推送。\n\n4. 如需更新镜像，请先获取更新，然后进行推送。\n\n   ```shell\n   git fetch -p origin\n   git push --mirror\n   ```\n\n## 其他阅读材料\n\n* [将更改从 GitHub Desktop 推送到 GitHub](/zh/desktop/making-changes-in-a-branch/pushing-changes-to-github-from-github-desktop#pushing-changes-to-github)\n* [关于 Git 大文件存储（Git Large File Storage）和 GitHub Desktop](/zh/desktop/configuring-and-customizing-github-desktop/about-git-large-file-storage-and-github-desktop)"}