GitHub mascot.

Using GitLab and GitHub at once

Using GitLab and GitHub simultaneously provides redundancy, better CI/CD options, and more collaboration opportunities. This guide explains how to set up and use GitLab and GitHub simultaneously in a project.

Using GitLab and GitHub at once? Yes!

There are multiple Git services available, but by far the two most popular are GitLab and GitHub. Using both GitLab and GitHub in a project is useful for various reasons, such as leveraging different CI/CD pipelines, maintaining a backup, or collaborating with teams using different platforms. In short, setting up multiple remotes and automating pushes, you can efficiently work with both platforms… or just giving you the option of having everything mirrored in two different services at once, and redundancy is always the way top go.


Setting Up Remote Repositories

First, clone your repository or create a new one:

git init

Add both GitLab and GitHub as remotes:

git remote add gitlab <gitlab-repo-url>
git remote add github <github-repo-url>

Verify the remotes:

git remote -v

The output should list both gitlab and github remotes.

Pushing to Both Repositories

To push changes to both remotes:

git push gitlab main
git push github main

To push to both simultaneously, use:

git push --all gitlab
git push --all github

Or, define a group remote:

git remote set-url --add --push origin <gitlab-repo-url>
git remote set-url --add --push origin <github-repo-url>

Then push using:

git push origin main

This sends updates to both repositories at once.

Fetching and Pulling from Both

To fetch from both remotes

git fetch --all

To pull from a specific remote:

git pull gitlab main
git pull github main

Keeping Both Repositories in Sync

If changes are made on both GitLab and GitHub, you need to merge them:

git pull gitlab main
git pull github main
git push origin main

Using CI/CD from Both Platforms

If using GitLab CI/CD, keep your .gitlab-ci.yml in the root directory. For GitHub Actions, create a .github/workflows/ directory and place YAML files there. Both systems can coexist as as long as their configurations do not interfere.


More Advanced Git topics

Leave a Reply

Your email address will not be published. Required fields are marked *