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:
- Log in to GitHub and beneath your avatar in the top right navigate to Settings.
- Toward the bottom of the left sidebar, click on Developer settings.
- Select Personal access tokens and then Fine-grained tokens.
- Click Generate new token.
- 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
- Repository permissions:
- 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:
- Log in to GitLab and go to your project.
- Navigate to Settings > Repository.
- Expand the Mirroring repositories section.
- Click New mirror.
- 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.
- Git repository URL:
- Set mirroring options:
- Enable Trigger pipelines for mirror updates to initiate CI/CD on updates.
- Click Mirror repository to save the configuration.
3. Verify the Mirroring Setup
Confirm that the mirroring is functioning correctly:
- In GitLab, navigate to Settings > Repository > Mirroring repositories.
- Click the Update Now button:
- Return to your GitLab Project home.
- Errors will display if there is an issue.
- Test by making a commit to the GitHub repository and verifying that the change appears in the GitLab repository after the next sync.