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

Phil Owen
by Phil Owen, Partner

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.

Github and Gitlabs character

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

AI in SEO: Why Entities and Context Matter More Than Keywords

Search technology is evolving and education providers need to adapt their strategies because change is essential for their success. The practice used to be to repeating "AAT courses" or "ACCA training" on a page, tweak metadata, build backlinks and make micro adjustments to influence the algorithm. But for UK education SMEs, the game has changed.

Read more

Is your website holding back your student enrolments?

In today’s competitive education market, your website is much more than a digital brochure – it’s the cornerstone of your student recruitment strategy. An outdated or poorly optimised website could be the reason your enrolments aren’t meeting expectations. At Sticky Digital, we’ve helped education providers like McArthur Morgan turn underperforming websites into powerful recruitment tools. Here are five key areas to review to ensure your website is set up for success.

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