1 min read

🧬 Push to Multiple Git Remotes Simultaneously (GitHub + GitLab)

You can configure your Git setup to push to multiple remotes at once by assigning multiple push URLs to a single remote. This is helpful when you're migrating to a repository or maintaining mirrors across platforms like GitHub and GitLab.

šŸ”§ Step-by-Step: Sync GitHub and GitLab Repositories

1. Inspect your current origin remote

git remote get-url origin
# https://github.com/<username>/<repo>.git

2. Rename origin to something descriptive

To distinguish between remotes, rename origin to github:

git remote rename origin github

3. Add your GitLab remote

Add a new remote pointing to GitLab:

git remote add gitlab https://gitlab.com/<username>/<repo>.git

4. Re-add origin for fetch/push management

Set up a new origin remote that:

  • Fetches from GitLab
  • Pushes to both GitLab and GitHub
git remote add origin https://gitlab.com/<username>/<repo>.git

5. Configure multiple push URLs

Add both GitLab and GitHub push endpoints to origin:

git remote set-url --add --push origin https://gitlab.com/<username>/<repo>.git
git remote set-url --add --push origin https://github.com/<username>/<repo>.git

āœ… Final Remote Configuration Check

Verify the setup:

git remote show origin

Expected output:

* remote origin
  Fetch URL: https://gitlab.com/<username>/<repo>.git
  Push  URL: https://gitlab.com/<username>/<repo>.git
  Push  URL: https://github.com/<username>/<repo>.git
  HEAD branch: main
  Remote branch:
    main tracked
  Local ref configured for 'git push':
    main pushes to main (up to date)

Let me know if you'd like this as a reusable shell snippet or wrapped into a small rust CLI tool.