Migrate Git repository with complete commit history

Migrate Git repository with complete commit history

Have you ever wonder how to move your entire git repository from one git server to other with complete commit history manually, Either it can be from GitHub to Bitbucket or anything you name it .

It's not a big deal, You can do it in just 4 easy steps :)

Quick:

git clone --mirror <url_of_old_repo>
cd <name_of_old_repo>
git remote add new-origin <url_of_new_repo>
git push new-origin --mirror

Detailed:

Step1: Set up a mirror of the source repository which you wish to migrate, Clone with --mirror download including remote-tracking branches, tags, notes etc

git clone --mirror <url_of_old_repo>

Step1.PNG

Step2: Change directory and you can see following folders

cd <name_of_old_repo>

Step2.PNG

Step3: Add new destination remote origin you wish to move to.

git remote add new-origin <url_of_new_repo>

image.png

Step4: Push entire repository to new origin, This might take a couple of minutes.

git push new-origin --mirror

Step4.PNG

That's it, Hope it helps. Let me know if you have better way to do it in comments below.