Import Repository from GitLab to GitHub

Overview

This document explains how to migrate a repository from GitLab to GitHub. This procedure assumes you:

  • have set up a GitHub account.
  • are a member of the GitHub organization and can create new reports.
  • have owner-level access to the GitLab repository that will be migrated.

Step-by-Step Process

Initiate the Migration Process

  1. Login to GitHub.
  2. Click the profile icon (upper right), and click Your Organization.
  3. Click the Repositories tab.
  4. Click New repository.
  5. Click Import a repository.
  6. Enter the GitLab repository URL in the Your old repository's clone URL field.
  7. Enter the organization in the Owner field.
  8. Enter the GitHub Repository Name.
  9. Select a Privacy level.
  10. Click Begin import.
    Note The import process will fail and then prompt you for credentials (unless the GitLab repository is public). Leave the Login form open and continue to step 11.
  11. Open a new browser window and navigate to the GitLab repository you are importing.
  12. In your GitLab repository, hover over the Settings  icon and select Repository.
  13. Under the Deploy Tokens section, click Expand.
  14. Enter importer in the Name and Username fields.
  15. Enter a date two days in the future in the Expiration date field.
  16. Check the read_repository, read_registry, and read_package_registry boxes.
  17. Click Create deploy token.
  18. Click the Clipboard  icon next to the Token field to copy it to your clipboard.
  19. Navigate back to the GitHub browser window.
  20. Enter importer in the Login field.
  21. Paste the token in the Password field.
  22. Click Submit.

Post-Migration GitHub Configuration

After the repository has successfully imported from GitLab to GitHub, use the Settings tab of your GitHub repository to configure the following as appropriate:

  • Collaborators and teams
  • Branches - Set a default branch and branch rules (e.g., it is common to require a pull request before merging)
  • Deploy keys - but note that GitHub only allows an SSH keypair to be used once system wide
  • And anything else your developers require

Remind developers to update any local references on their workstations by navigating to the repository and setting the new remote URL:

cd /local/path/to/repo

# Click Code on your GitHub repo page to copy the URL, and use it below in place of git@github.com:..
git remote set-url origin git@github.com:foo-org/nice-repo.git

# Confirm the new remote setting
git remote -v

Finally, any automation (batch jobs, CI/CD pipelines) need to be updated to use the GitHub repository.

Post-Migration GitLab Cleanup

NB: Archiving your GitLab repository may be a good idea in order to prevent accidental commits. 
Note Get buy-in from your team before proceeding as this changes the repository to read-only.

After getting buy-in, and after the repository has successfully migrated from GitLab to GitHub:

  1. In your GitLab repository, hover over the Settings  icon and click General.
  2. Under the Advanced section, click Expand.
  3. Under the Archive project section, click Archive project.
Tags: 
Last Updated: 
Monday, February 13, 2023