Skip to main content

此版本的 GitHub Enterprise 已停止服务 2022-10-12. 即使针对重大安全问题,也不会发布补丁。 为了获得更好的性能、更高的安全性和新功能,请升级到最新版本的 GitHub Enterprise。 如需升级帮助,请联系 GitHub Enterprise 支持

Importing a Git repository using the command line

Importing Git projects using the command line is suitable when your existing code is hosted on a private network.

Before you start, make sure you know:

  • Your GitHub Enterprise Server username
  • The clone URL for the external repository, such as https://external-host.com/user/repo.git or git://external-host.com/user/repo.git (perhaps with a user@ in front of the external-host.com domain name)

For purposes of demonstration, we'll use:

  • An external account named extuser
  • An external Git host named https://external-host.com
  • A GitHub Enterprise Server personal account named ghuser
  • A repository on your GitHub Enterprise Server instance named repo.git
  1. Create a new repository on GitHub Enterprise Server. You'll import your external Git repository to this new repository.
  2. On the command line, make a "bare" clone of the repository using the external clone URL. This creates a full copy of the data, but without a working directory for editing files, and ensures a clean, fresh export of all the old data.
    $ git clone --bare https://external-host.com/EXTUSER/REPO.git
    # Makes a bare clone of the external repository in a local directory
  3. Push the locally cloned repository to GitHub Enterprise Server using the "mirror" option, which ensures that all references, such as branches and tags, are copied to the imported repository.
    $ cd REPO.git
    $ git push --mirror https://hostname/USER/REPO.git
    # Pushes the mirror to the new repository on your GitHub Enterprise Server instance
  4. Remove the temporary local repository.
    $ cd ..
    $ rm -rf REPO.git