使用命令行导入 git 仓库

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

Were you able to find what you were looking for?

Yes, easily Yes, eventually No Send

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

  • 您的 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 仓库。

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

    $ git clone --bare https://external-host.com/extuser/repo.git
    # Makes a bare clone of the external repository in a local directory
    
  3. 使用“镜像”选项将本地克隆的仓库推送到 GitHub,以确保所有引用(如分支和标记)都复制到导入的仓库。

    $ cd repo.git
    $ git push --mirror https://github.com/ghuser/repo.git
    # Pushes the mirror to the new GitHub repository
    
  4. 删除临时本地仓库。

    $ cd ..
    $ rm -rf repo.git
    

打赏一个呗

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦