In software development, version control repositories are essential for managing codebases. At times, developers may need to synchronize repositories between platforms—such as GitLab and GitHub—to maintain backups, improve collaboration, or increase visibility. This guide demonstrates how to mirror a GitLab repository to GitHub in a step-by-step manner.
Mirroring is the process of creating and maintaining an exact replica of a repository. Unlike forking, which only copies the current state, mirroring retains all branches, tags, commit histories, and references, and can stay continuously synchronized with the original.
- Backup: Keep a secondary copy of your work.
- Cross-Platform Collaboration: Collaborate with users on different platforms.
- Continuous Sync: Keep GitHub updated automatically as changes are pushed to GitLab.
- Complete History: Retains commit history and branch structure, unlike forks.
To configure push mirroring so that updates pushed to GitLab are automatically reflected in GitHub.
- GitLab: DevOps platform for source control and CI/CD
- GitHub: Widely used Git hosting platform for code collaboration
- Git (CLI): Command-line tool for version control
- PAT (Personal Access Token): Secure credential to authenticate between services
- Log in to GitHub.
- Click on
+
➝New Repository
. - Set repository name:
Gitlab-Repo-Mirroring
. - Select visibility: Public.
- Check: “Initialize this repository with a README”.
- Click Create Repository.
- Go to Settings ➝ Developer Settings.
- Click Personal Access Tokens ➝ Tokens (classic).
- Click Generate new token (classic).
- Note description: "Mirroring GitLab to GitHub".
- Select all scopes (full access).
- Click Generate Token.
- Copy and store the token securely. (One-time view only)
- Log in to GitLab ➝
New Project
➝Create Blank Project
. - Project Name:
GitHub-Repo-Mirroring
. - URL Namespace: Select
Users
. - Visibility: Public.
- Initialize repository with a README.
- Click Create Project.
- Navigate to your GitLab project.
- Go to
Settings
➝Repository
. - Scroll to Mirroring repositories ➝ Click Add New Mirror.
- Git Repository URL:
- Authentication Method: Username + Token
- Username: Your GitHub username
- Password/Token: Paste the GitHub PAT you generated
- Click Mirror Repository
-
Clone your GitLab repository locally:
git clone https://gitlab.com/<your-username>/GitHub-Repo-Mirroring.git cd GitHub-Repo-Mirroring
-
Create and add a new file:
touch testfile.txt
git add .
git commit -m "Added test file for mirror sync"
git push
-
Go to GitHub ➝ Refresh the repository ➝ Confirm testfile.txt appears.
-
Go to GitLab ➝ Refresh the repository ➝ Confirm testfile.txt appears.
This guide demonstrates how to set up automatic GitLab-to-GitHub mirroring using push mirroring with PAT authentication. Once configured, any change pushed to GitLab is automatically reflected in GitHub, enabling smooth backups and collaboration across both platforms.