How to Import an Existing Git Repository into GitHub

Recently I’ve had to move a number of git repositories off a private server and onto GitHub. Here’s how to do that.

(Based on GitHub’s own howto, but with a bugfix.)

1. Create a bare clone of the existing repo from your server.

$ git clone --bare

This will create a local directory named repo.git.

2. Create a new repo on your GitHub account.

Go directly to the Create a New Repo page on GitHub, or read the more detailed instructions.

3. Push the local cloned repository to GitHub using the “mirror” option.

This way ensures that all branches and tags are preserved in the imported repository.

$ cd repo.git
$ git push --mirror [email protected]:yourname/repo.git

4. Remove the local cloned repo.

$ cd ..
$ rm -rf repo.git

5. Check out your new repo on GitHub:

6. Finally, clone the new GitHub repo onto your local machine.

$ git clone [email protected]:yourname/repo.git
$ cd repo

Continue developing from there.