Migrating a Repository Between Platforms Without Losing Git History

Beda Arta
GitBitbucketGitHub

You might want to migrate your repository from one platform to another without losing its Git history, as I did. For example, my current repository is stored on GitHub, and for some reason I want to migrate it to Bitbucket. However, one of the problems when migrating from one platform to another is preserving the Git history, I don’t want to lose all previous commits.

Create a New Repository

First, create a new repository on where you want to migrate. In my case, I created a new repository on Bitbucket.

Check Git Remote URL

Next, check git remote URL of your project on your machine by running this command.

git remote -v

If your repository is stored on GitHub, then you will see something like this one:

origin	[git@github.com](mailto:git@github.com):bedaarta/project.git (fetch)
origin	[git@github.com](mailto:git@github.com):bedaarta/project.git (push)

Update Git Remote URL

Then, to migrate it to Bitbucket, set the Git remote URL to the new one. You can find the new Git remote URL on the settings page of your new repository on Bitbucket.

git remote set-url origin git@bitbucket.org:bedaarta/project.git

Test

Make sure the Git remote URL is now set to Bitbucket instead of GitHub.

git remote -v 

You should see something like this:


origin	[git@bitbucket.org](mailto:git@bitbucket.org):bedaarta/project.git (fetch)
origin	[git@bitbucket.org](mailto:git@bitbucket.org):bedaarta/project.git (push)

Once you're done with the steps above, you can push your new commits to Bitbucket, and you also won't lose your Git history.