Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save albertpark/fcb5a0853b78775cc9bbf84c88d05ce1 to your computer and use it in GitHub Desktop.
Save albertpark/fcb5a0853b78775cc9bbf84c88d05ce1 to your computer and use it in GitHub Desktop.

Importing a Git repository using the command line

Before you start, make sure you know:

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

References
Importing a Git repository using the command line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment