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

That very easy, If you have a project hosted on another version control system, you can automatically import it to GitHub using the GitHub Importer tool.

  1. In the upper-right corner of any page, click , and then click Import repository.

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

Since GitHub Importer is not suitable for my purposes, then I tried to import repo using git basic commands

  1. First I created a repository in GitHub
$ 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

Node GitLab to GitHub migrate Issues, milestones etc from gitlab to github. You can find it from here.

Conclusion

I’m satisfied with both Method 2 and Method 3 but getting import repository from GitLab to GitHub bit difficult. But the inverse import that means GitHub repository to GitLab is really easy 🙂 . GitLab Repository Importer import everything. See the docs from here.

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