Import – Export Git Repo

The wonderful thing about Git is that it does not only store your files but also the history of each of them. If you wish to change your repository without starting from scratch (i.e. retain your commits, branch, etc.), you can export the old repository and import it to the new one.

Here’s a step-by-step guide:

1. Clone the old repository with the ‘bare’ option to get a full copy of the git data (commits, branch, etc.) without the working directory.

git clone --bare <old-repo-to-be-imported.git>

2. Push the bare cloned repository to the new repository with the ‘mirror’ option to retain in the new repo all git data from the old.

cd <exported-repo.git>
git push --mirror <new-repo.git>

3. Remove the local repository; you don’t need it. Clone your new repository.

cd .. && rm -rf <exported-repo.git>
git clone <new-repo.git>

Source: https://help.github.com/articles/importing-an-external-git-repo

2 comments

  1. Hello! I just want to give an enormous thumbs up for the good data you¡¦ve
    right here on this post. I will probably be coming again
    to your blog for extra soon.

  2. Great article.

Leave a comment