At work we have been using GitLab for a while and it’s been pretty good but we have recently opted to move to GitHub Enterprise. As a result there are a number of small repos we have hosted on GitLab that now need to be moved over to GitHub.
Additionally, this should generically work for any git repository migration but I’m explicitly calling out “gitlab” and “github” in hopes it makes the post easier to follow — and because it’s my actual use case.
The process is as follows:
- Mirror clone the old repo @ GitLab
- Mirror push to the new repo @ GitHub with pre-commit hooks skipped
- Update the push URL for the mirror cloned repo
Why clone as `mirror`?
Because it’s like `–bare` but with more magic!
This blurb from the git docs pretty much covers it:
Set up a mirror of the source repository. This implies –bare. Compared to –bare, –mirror not only maps local branches of the source to local branches of the target, it maps all refs (including remote-tracking branches, notes etc.) and sets up a refspec configuration such that all these refs are overwritten by a git remote update in the target repository.
And from GitHub’s docs:
As with a bare clone, a mirrored clone includes all remote branches and tags, but all local references will be overwritten each time you fetch, so it will always be the same as the original repository.
Why skip pre-commit hooks?
You may not need to do this but the repos I’ve been working on have a lot of pre-commit stuff that runs — tests, static analysis, etc. For the purpose of just pushing the entire repo to a new location i don’t care about this stuff. `–no-verify` tells git to push and skip the hooks.
Repo Migration Process
Developer Change Process
For developers who are using the repos being migrated, the process for pointing @ GitHub is a one liner.