Migrating Git repositories permalink
I recently needed to migrate our company’s git repositories from GitHub to an on-prem BitBucket instance without completely blocking the on-going work of >100 engineers. While Atlassian provides a tool to import, I couldn’t find the tool in our instance of BitBucket and had to resort to the built-in tools in git as described in the GitHub documentation:
-
Make a bare mirrored clone of the repository
git clone --mirror https://github.com/exampleuser/repository-to-mirror.git cd repository-to-mirror.git
-
Set the push location on the mirror to your new remote
git remote set-url --push origin https://git.ourserver.com/exampleuser/mirrored.git git push --mirror
-
Update from original repository in case changes are made
git remote update
Once I had the commands down, it was just a matter of coordination and ordering. My approach followed these basic steps:
- Create users and groups in BitBucket (This was actually done for my since we had integrated our ActiveDirectory server with BitBucket).
- Setup a Jenkins user with public SSH key so that our Jenkins jobs can clone repositories to build
- Create a new, empty repo in BitBucket
- Run through the steps above, using the new BitBucket repo
- Clone Jenkins jobs, disable them (so they don’t accidentally cause race conditions with the existing jobs) and update them to use the new BitBucket repo
- Disable the old Jenkins jobs.
- Enable the new Jenkins jobs and test them.
- Restrict access to the old GitHub repository so that no one can write to it
- Update the mirror from the old GitHub repository and push to BitBucket
- Notify everyone to update their local repositories using
git remote set-url origin https://git.ourserver.com/exampleuser/mirrored.git
- Delete old Jenkins jobs
- Set a reminder to delete the old repository in 2 sprints.