Skip to content

Commit e7c9429

Browse files
committed
Add a post about pushing to both GitHub and GitLab in one git command
1 parent bacf98c commit e7c9429

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
date: '2026-02-20'
3+
title: Push to GitHub and GitLab Simultaneously with Git
4+
description: A neat Git trick to configure multiple push URLs on a single remote so you can mirror your repositories with every push.
5+
---
6+
## Push to GitHub and GitLab Simultaneously with Git
7+
8+
If you're like me and you maintain mirrors of your repositories on both GitHub and GitLab, you've probably gotten used to running `git push` twice or writing a shell alias to push to both. There's a cleaner way built right into Git that most people don't know about: multiple push URLs on a single remote.
9+
10+
### Setting It Up
11+
12+
Say your `origin` remote points to GitLab and you want to also push to GitHub. You can add a second push URL like this:
13+
14+
```bash
15+
git remote set-url --add --push origin [email protected]:dylanmtaylor/myrepo.git
16+
git remote set-url --add --push origin [email protected]:dylanmtaylor/myrepo.git
17+
```
18+
19+
The order here matters. The `--add --push` flag creates a separate push URL list for the remote. Once that list exists, Git stops using the fetch URL for pushes. So the first command ensures your original GitLab URL is still a push target, and the second adds GitHub alongside it.
20+
21+
After running these commands, `git remote -v` will show something like:
22+
23+
```
24+
origin [email protected]:dylanmtaylor/myrepo.git (fetch)
25+
origin [email protected]:dylanmtaylor/myrepo.git (push)
26+
origin [email protected]:dylanmtaylor/myrepo.git (push)
27+
```
28+
29+
### How It Works
30+
31+
Now every `git push origin` pushes to both URLs sequentially. Pulls and fetches still come from the single fetch URL, so your primary host remains the source of truth. There's no risk of merge conflicts between the two — they always receive the same commits at the same time.
32+
33+
This is especially useful when combined with CI/CD. In my case, GitLab is used to deploy to my production Kubernetes cluster, while GitHub Actions builds and deploys to GitHub Pages as a mirror. One push triggers both pipelines.
34+
35+
It's a small configuration change, but it completely eliminates the "forgot to push to the mirror" problem.

0 commit comments

Comments
 (0)