Migrate Git repository from Bitbucket to GitHub
Hey 👋, recently I wanted to play with GitHub Actions and this blog (upcoming post 👀) and I realised that I had this repository still in Bitbucket.
So I decided to migrate the Git repository from Bitbucket to GitHub.
Here’s what I needed to do:
- Made a fresh new clone of my Bitbucket repository to a new localtion
git clone --mirror <bitbucket-repository>
- Removed the
originremote, so that we can set the new one from GitHub.
git remote rm origin
- Went to GitHub and created the new repository (a private repository in my case).
- Added the new
originremote from GitHub.
git remote add origin <github-repository>
- Push everything to GitHub’s remote.
git push --mirror origin
- Now, I went and ‘cloned’ the new GitHub repository to confirm everything was fine.
git clone <github-repository>
- After confirming the new cloned repository has everything I removed the one we used for migration.
Some extra notes:
- I used
--mirrorwhen cloning the Bitbucket repository because that way you download all the tags/branches.
--barewhich clones a bare repository, which means not having a working tree that’s why I deleted it in the last step.
- If you had any submodule (weird, right?) you will need to run
git submodule initand
git submodule updateat the end too.
Was this helpful to make the switch to GitHub? Let me know by clicking on the 👍 button below!