阅读(2306) (0)

GitHub 使用命令行导入 Git 仓库

2020-08-19 15:24:14 更新

如何 GitHub Importer 不适用于您的目的,例如,如果您现有的代码托管在私有网络上,则我们建议使用命令行导入。

在开始之前,请确保您知道:

  • 您的 GitHub 用户名
  • 外部仓库的克隆 URL,如 https://external-host.com/user/repo.gitgit://external-host.com/user/repo.git(或许 external-host.com 域名前面是 user@

为便于示范,我们将使用:

- 外部帐户 extuser
- 外部 Git 主机 https://external-host.com
- GitHub 个人用户帐户 ghuser
- GitHub 仓库 repo.git

  1. 在 GitHub 上创建新仓库。 您将在此新仓库中导入外部 Git 仓库。

  1. 在命令行上,使用外部克隆 URL 创建仓库的“裸”克隆。 这会创建数据的完整副本,但没有编辑文件的工作目录,并确保干净、新鲜地导出所有旧数据。

   $ git clone --bare https://external-host.com/extuser/repo.git
   # Makes a bare clone of the external repository in a local directory

  1. 使用“镜像”选项将本地克隆的仓库推送到 GitHub,以确保所有引用(如分支和标记)都复制到导入的仓库。

   $ cd repo.git
   $ git push --mirror https://github.com/ghuser/repo.git
   # Pushes the mirror to the new GitHub repository

  1. 删除临时本地仓库。

   $ cd ..
   $ rm -rf repo.git