Introduction
Recently, I planned to migrate GitLab to GitHub at work, but finding the time for the project migration felt troublesome, leading to many plans being delayed, such as building a CI automated testing environment and implementing AI code review.
Fortunately, GitLab has had a feature called Mirroring that allows you to sync a Git Repo to other locations in three ways, quickly establishing GitLab Repo sync via a simple web interface:
- Push: Sync your GitLab Repo to another Repo
- Pull: Sync another Repo to GitLab
- Bidirectional: Two-way sync
Except for the Push service, which is free, the rest require payment. This article describes how to set up GitLab push GitHub to achieve cross-platform code migration based on my migration experience.
GitLab Push
Prepare the GitLab Repo to be migrated and create a brand new GitHub Repo.
- Go to the target GitLab Repo
- Sidebar Settings > Repository
- Open Mirroring repositories > Add New
- Enter the Git repository URL.
The repository must be accessible over http://, https://, ssh:// or git://.When using the http:// or https:// protocols, please provide the exact URL to the repository. HTTP redirects will not be followed.Do not include the username in the URL, use the username field below if required: https://gitlab.company.com/group/project.git.When using the ssh:// protocol, please use the following format: ssh://[email protected]/group/project.git.The update action will time out after 180 minutes. For big repositories, use a clone/push combination.Pull mirrors will only create LFS objects if LFS is enabled for the project.Push mirrors will only sync LFS objects if LFS is enabled for the project.Push mirrors will not sync LFS objects over SSH.In case of pull mirroring, your user will be the author of all events in the activity feed that are the result of an update, like new branches being created or new commits being pushed to existing branches.You will notice that there are many descriptions in that field. I didn’t have the patience to read through it all, and it cost me a lot of time 🫠. In any case, you can go to the “target GitHub Repo’s account” to create a personal access token (Settings > Developer Settings > Personal access tokens), there are two types:
- Fine-grained (permissions are more precise to the Repo level, requires
contentsread and write access) - classic (traditional, requires
Repopermissions)
Finally, let’s assume the GitHub username is foobar, and the Repo name is sync-demo.
- Git repository URL
https://github.com/foobar/sync-demo.git
- Authentication method (Username and Password)
- Username
- foobar
- Password
- The previously created access token
- Username
After creating the Mirror, you will see it automatically sync the contents of both Repos, and you can also trigger it manually. It’s a bit like a ready-made CI, very convenient and fast.