The Ultimate Dual-Push Workflow: Seamlessly Syncing GitHub and GitLab with a Single Command
Many developers and engineering teams maintain presence across both GitHub and GitLab.
Perhaps you love GitHub for its open-source discovery, community stars, and GitHub Actions, but you rely on GitLab for its enterprise CI/CD pipelines, issue management, and the GitLab Contributor Program. Or perhaps you simply want instant off-site redundancy so your code is never locked into a single vendor.
However, manually running:
git push github main
git push gitlab main
is tedious, error-prone, and inevitably leads to repository divergence.
In this guide, I will show you how to set up an automated, zero-maintenance dual-push architecture where a simple git push origin main updates both GitHub and GitLab in parallel, complete with verified cryptographic commit signatures across both platforms.
1. How Git Handles Multi-Push Remotes
Under the hood, Git allows a single remote (such as origin) to have:
-
One fetch URL: Where
git pullorgit fetchretrieves commits from. -
Multiple push URLs: Where
git pushsends commits sequentially or concurrently.
When you configure multiple push URLs on origin, running git push origin main tells Git to iterate through every registered push endpoint and replicate your commits across all targets.
2. The Step-by-Step Configuration
Step A: Adding Dual Push URLs to an Existing Repo
If you already have a repository cloned with GitHub as origin:
# 1. Keep GitHub as the primary fetch URL and first push destination
git remote set-url --add --push origin git@github.com:USERNAME/REPO.git
# 2. Add GitLab as a secondary push destination
git remote set-url --add --push origin git@gitlab.com:USERNAME/REPO.git
Step B: Inspecting the Remote Configuration
Run git remote -v to verify your endpoints:
origin git@github.com:USERNAME/REPO.git (fetch)
origin git@github.com:USERNAME/REPO.git (push)
origin git@gitlab.com:USERNAME/REPO.git (push)
Now, when you run:
git push origin main
Git outputs:
Enumerating objects: 15, done.
Writing objects: 100% (15/15), done.
To github.com:USERNAME/REPO.git
a1b2c3d..e4f5g6h main -> main
To gitlab.com:USERNAME/REPO.git
a1b2c3d..e4f5g6h main -> main
Both platforms are updated instantly.
3. The One-Line Automation: Creating a Global Git Alias
Instead of typing those configuration commands for every new project, automate it with a custom Git alias in your global ~/.gitconfig:
git config --global alias.dual-sync '!f() { \
repo="${1:-$(basename "$PWD")}"; \
git remote get-url origin >/dev/null 2>&1 || git remote add origin "git@github.com:USERNAME/$repo.git"; \
git remote set-url --add --push origin "git@github.com:USERNAME/$repo.git" 2>/dev/null || true; \
git remote set-url --add --push origin "git@gitlab.com:USERNAME/$repo.git"; \
echo "✅ Configured dual-push to GitHub & GitLab for $repo:"; \
git remote -v; \
}; f'
How to Use It:
Whenever you create or clone a new repository:
cd my-new-project
git dual-sync
Git immediately configures both GitHub and GitLab push endpoints automatically based on the current directory name.
4. Cryptographic Trust: Verified Commits on Both Platforms
To maintain high trust, your commits should display the "Verified" badge on both GitHub and GitLab.
Modern Git allows signing commits using your existing SSH keys (ED25519) instead of dealing with clumsy GPG setups.
Step A: Configure Git to Sign with SSH
# Set SSH as the signing format
git config --global gpg.format ssh
# Point to your public SSH key
git config --global user.signingkey ~/.ssh/id_ed25519.pub
# Enable auto-signing on all commits
git config --global commit.gpgsign true
Step B: Add Public Key to Both Platforms
- On GitHub: Go to Settings $\rightarrow$ SSH and GPG keys $\rightarrow$ Add New SSH Key $\rightarrow$ Select Key type: Signing Key.
- On GitLab: Go to Edit Profile $\rightarrow$ SSH Keys $\rightarrow$ Paste key and ensure "Signing" usage is checked.
Now, whenever you git commit -m "feat: new engine" and push via git dual-sync, both GitHub and GitLab show green Verified badges next to every commit author.
5. Handling CI/CD Across Both Ecosystems
With dual-push in place, you can leverage the best features of both ecosystems:
-
.github/workflows/ci.yml: Triggers on GitHub for fast pull request checks and GitHub Pages deployments. -
.gitlab-ci.yml: Triggers on GitLab for enterprise container builds, SAST security scans, and integration tests.
Neither platform conflicts with the other. Each ignores the other platform's configuration file, giving you the best of both worlds in a single codebase.
6. Key Benefits
- Vendor Independence: If one platform has scheduled maintenance or unexpected downtime, your workflow continues uninterrupted on the other.
- Double Discovery: Your work reaches both the GitHub developer ecosystem and the GitLab community.
-
Automated Redundancy: Off-site backups happen organically with every
git push.
Links & Community
- GitLab Profile: gitlab.com/hrlpavan
- GitLab Contributor Profile: contributors.gitlab.com/users/hrlpavan
- GitHub: github.com/hrlpavan
How do you handle multi-remote backups in your development team? Let’s discuss in the comments below!
Top comments (0)