How to setup git mirroring from a private Github repository to GitLab

by Phil Owen, Partner

How to Setup Git Mirroring from Private GitHub Repository to GitLab

Learn how to mirror your private GitHub repository to GitLab, enabling seamless CI/CD deployment pipelines. This is useful if you continue to use your GitHub private repository as the primary team repo and want to benefit from GitLab's excellent deployment services.

1. Create a Fine-Grained Personal Access Token (PAT) on GitHub

To securely mirror your repository, generate a fine-grained PAT with read-only permissions:

  1. Log in to GitHub and beneath your avatar in the top right navigate to Settings.
  2. Toward the bottom of the left sidebar, click on Developer settings.
  3. Select Personal access tokens and then Fine-grained tokens.
  4. Click Generate new token.
  5. Configure the token:
    • Token name: Enter a descriptive name.
    • Expiration: Set an appropriate expiration date.
    • Resource owner: Choose the relevant GitHub account or organization name.
    • Repository access: Select the specific repositories to access.
    • Permissions:
      • Repository permissions:
        • Contents: Read-only
        • Metadata: Read-only
  6. Click Generate token and save the token securely.

Note: Fine-grained PATs provide enhanced security by allowing precise permission settings.

2. Set Up Repository Mirroring in GitLab

Configure GitLab to mirror your GitHub repository:

  1. Log in to GitLab and go to your project.
  2. Navigate to Settings > Repository.
  3. Expand the Mirroring repositories section.
  4. Click New mirror.
  5. Enter the repository information:
    • Git repository URL: https://github.com/<user-or-organization-name>/<repository-name>.git
    • Mirror direction: Select Pull.
    • Authentication method: Choose Username and Password, and for username, enter <user-or-organization-name>. For the password, enter your PAT.
  6. Set mirroring options:
    • Enable Trigger pipelines for mirror updates to initiate CI/CD on updates.
  7. Click Mirror repository to save the configuration.

3. Verify the Mirroring Setup

Confirm that the mirroring is functioning correctly:

  1. In GitLab, navigate to Settings > Repository > Mirroring repositories.
  2. Click the Update Now button:
    • Return to your GitLab Project home.
    • Errors will display if there is an issue.
  3. Test by making a commit to the GitHub repository and verifying that the change appears in the GitLab repository after the next sync.

More articles

Is your website holding back your student enrolments?

Discover five critical areas to optimise your education website for recruitment success. From navigation tweaks to SEO strategies, we’re here to help you make an impact.

Read more

How a strong online presence can revolutionise student enrolment

Learn how thoughtful digital strategies can empower education providers across the UK to lead the way in student engagement.

Read more

Get in touch – we’d love to help

Whether you’re looking for innovative solutions or a long-term partner who’s as invested in your success as you are, we’re here for you.

Our offices

  • Hampshire
    Gatcombe House
    Copnor Road, Hilsea
    Portsmouth, Hants PO3 5EJ
    Tel +44 (0)2392 380 457