Source Repository Migration from GitLab to GitHub

Today I was looking for a way to migrate GitLab repository to GitHub without losing commit history. In my case I wanted to import from private GitLab to GitHub. So, I came up with a few options for get this done.

Method 1: GitHub Repository Importer

  1. In the upper-right corner of any page, click , and then click Import repository.
  2. Under “Your old gitlab repository’s clone URL”, type the URL of the project you want to import.
  3. Choose your user account or an organization to own the repository, then type a name for the repository on GitHub. Specify whether the new repository should be public or private. Then click on begin import

GitHub Importer is not suitable for all imports. For example, if your existing code is hosted on a private network, our tool won’t be able to access it. In these cases, we recommend importing using the command line for Git repositories or an external source code migration tool for projects imported from other version control systems.

I couldn’t use this method since the GitHub importer only accepts public GitLab repositories.

Method 2: Using a Simple Shell Script

  1. First I created a repository in GitHub
  2. Then I bare cloned the repository using below command
$ git clone --bare https://<GITLAB_DOMAIN>.com/<USER>/<REPO_NAME>.git

When you use the — bare parameter with git clone, you’ll get a copy of the remote repository with no working directory. This indicates that a repository will be created with the project’s history, which may be pushed and pulled from but not directly modified. Furthermore, with the — bare repository, no remote branches for the repo will be enabled.

3. Push the locally cloned repository to GitHub using the “mirror” option

$ cd <REPO_NAME>.git
$ git push --mirror https://github.com/<USERNAME>/<REPOSITORY>.git

This guarantees that any references to the imported repository, such as branches and tags, are copied.

For the better use I created a shell script using above git command because in that way I will be able to reuse this command at once. I pushed the script to GitHub you can find it from here.

This script worked form me but that didn't migrate Pull Request and Issues data so I was keep looking and I found an another NodeJS app which can do that as well.

Method 3: node-gitlab-2-github

Conclusion

Chamod Shehanka a FullStack Developer at Platformer and Writer at Noteworthy, Platformer and The Java Report