Skip to content

GitLab to GitHub

https://gitlab.cern.ch is the default code hosting platform at CERN, but has limitations for external contributors. We recommend GitHub when external contributions are expected. This guide explains how to migrate from the former to the latter.

Before you start with migration:

  • Make sure that confidential information is not exposed. In other words, passwords, and secrets are not in code. You might need to check your git history of the files that could use passwords. Exposing even a test password might have an impact. (You can refer to this KB article about how to delete parts of git's history for a file)
  • Verify your project so personal data and sensitive personal data are not present.
  • Don’t expose pseudonymisation algorithms that would allow a third party to deanonymize public data (if applicable)
  • Don’t expose internal CERN resources to avoid attacks
  • It is essential to indicate the copyright and license.

Migration options

  1. GitHub provides a migration tool for workflows / actions.
  2. For manual migrations, you can follow the official documentation.
  3. Mirror the GitHub project on GitLab: Mirror

Authors

  • Most likely you were not working on the project alone. So all the user accounts are not the same anymore. In this case, we encourage you to contact your colleagues or ex-colleagues to update their GitHub accounts.
  • GitHub provides a possibility to change primary e-mail addresses as well as add additional email addresses as described here

CI/CD

  • GitLab and GitHub syntax is different but have similar characteristics in the way that the jobs can run sequentially, on separate machines or containers and in parallel. In both repositories, it is possible to configure self-hosted or managed runners. Also, both support docker images.
  • Note that GitLab Merge Requests (MRs) and GitHub Pull Requests (PRs) are not the same. So make sure that all MRs are resolved.

Issues migration

GitLab's issues are stored in the GitLab's database, and are not stored in Git itself. That is why you need to export them from the GitLab first and import in GitHub using the APIs. Here is how you can do it with python script:

  1. Install GitLab python package:

    pip install python-gitlab
    
  2. Execute following script (follow this documentation to get personal token):

    import gitlab
    import csv
    
    # Connect to GitLab
    gl = gitlab.Gitlab('https://gitlab.cern.ch/', private_token='your private token')
    
    # Get the project
    project = gl.projects.get('your-namespace/your-project')
    
    # Get all issues
    issues = project.issues.list(all=True)
    
    # Define the CSV file
    with open('gitlab_issues.csv', 'w', newline='') as csvfile:
       fieldnames = ['id', 'title', 'description', 'state', 'created_at', 'updated_at', 'closed_at', 'labels']
       writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
    
       writer.writeheader()
       for issue in issues:
           writer.writerow({
               'id': issue.id,
               'title': issue.title,
               'description': issue.description,
               'state': issue.state,
               'created_at': issue.created_at,
               'updated_at': issue.updated_at,
               'closed_at': issue.closed_at,
               'labels': ','.join(issue.labels)
           })
    
  3. Install GitHub python package:

    pip install PyGithub
    
  4. Run following script (follow this documentation to get personal token):

    import csv
    from github import Github
    
    # Connect to GitHub
    g = Github('your private token')
    
    # Get the repository
    repo = g.get_repo('your-namespace/your-project')
    
    # Read issues from CSV
    with open('gitlab_issues.csv', newline='') as csvfile:
        reader = csv.DictReader(csvfile)
        for row in reader:
            issue = repo.create_issue(
                title=row['title'],
                body=row['description'],
                labels=row['labels'].split(',')
            )
    

Don’t forget to archive your project in GitLab once you ensure that migration is successful.