👋 We've unified all of GitHub's product documentation in one place! Check out the content for REST API, GraphQL API, and Developers. Learn more on the GitHub blog.
Article version: Enterprise Server 2.20

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.

Were you able to find what you were looking for?

Before you start, make sure you know:

  • Your GitHub Enterprise 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 personal user account named ghuser
  • A GitHub Enterprise repository named repo.git
  1. Create a new repository on GitHub Enterprise. 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 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/ghuser/repo.git
    # Pushes the mirror to the new GitHub Enterprise repository
  4. Remove the temporary local repository.
    $ cd ..
    $ rm -rf repo.git

Were you able to find what you were looking for?

Ask a human

Can't find what you're looking for?

Contact us