In this example, I'll demonstrate one way of migrating a repository from GitLab to GitHub. Sounds simple enough? Kinda? Here are the requirements and a caveat.
- Preserve as much history as possible (e.g. tags, branches, commits, merges, etc.).
- The GitLab repo is on premise and is only accessible through the organization VPN.
Now this would have been easy if your GitLab repo can be seen by GitHub. Sadly it can't because your repo is behind a firewall. What do we do now? Well the good thing is both are git repositories. I did these steps on a Windows 11 machine with git for Windows v2.44.
-
Create a new repo on GitHub. Make sure to name it the same as the one on GitLab.
-
On git bash, make a "bare" clone of the GL (GitLab) repo in your local machine. This creates a full copy of the data, but without a working directory for editing files, and ensures a clean, fresh export of all the old data.
# $ git clone --bare https://gitlab-host.com/username/repo.git $ git clone --bare https://gitlab.com/jpllosa/migration-demo.git Cloning into bare repository 'migration-demo.git'... remote: Enumerating objects: 11, done. remote: Counting objects: 100% (11/11), done. remote: Compressing objects: 100% (8/8), done. remote: Total 11 (delta 3), reused 0 (delta 0), pack-reused 0 Receiving objects: 100% (11/11), done. Resolving deltas: 100% (3/3), done.
-
Push the locally cloned repository to GH (GitHub) using the "mirror" option. This ensures that all references, such as branches and tags, are copied to the imported repository.
# $ cd repo.git # $ git push --mirror https://github.com/username/repo.git $ cd migration-demo.git/ user@hostname MINGW64 /c/temp/migration-demo.git (BARE:main) $ git push --mirror https://github.com/jpllosa/migration-demo.git Enumerating objects: 11, done. Counting objects: 100% (11/11), done. Delta compression using up to 20 threads Compressing objects: 100% (5/5), done. Writing objects: 100% (11/11), 3.57 KiB | 3.57 MiB/s, done. Total 11 (delta 3), reused 11 (delta 3), pack-reused 0 (from 0) remote: Resolving deltas: 100% (3/3), done. To https://github.com/jpllosa/migration-demo.git * [new branch] branch-two -> branch-two * [new branch] main -> main * [new tag] v1.0 -> v1.0
As you can see from above, it looks like everything got copied over. Branches, tags and all that jazz. A thing to note though, if you got various git accounts from different git servers then you might need to change some configuration before you can push. See
git config
command for more details. -
All done. You can now remove the temporary local repo and then use the GH repo from now on.
cd .. rm -rf REPO.git
GitLab to GitHub Migration
Were the branches preserve? As can bee seen below, it has been.
Were the tags preserve? As can bee seen below, it has been.
Were the commits preserve? As can bee seen below, it has been.
Awesome! That was a successful migration. Great job!
Some Reminders
- On GH don't forget to configure the default branch settings, add collaborators and teams, etc.
-
If your repo is a Maven project, don't forget to update the
scm
details. - Don't forget to update your CI/CD pipelines. For example update your Jenkins job to pull from the new GH repo.
GitLab to GitHub Migration Closing
Now you know how to migrate your git repo from GL to GH. Everything got preserved as well even when your GL server was behind a firewall.