Pushing git code to multiple mirrors

27.02.2025

There’s an easy way to push to multiple remotes with one command: give the same remote multiple push URLs.

Say you cloned repository.

$ git remote -v
origin  [email protected]:user/repository (fetch)
origin  [email protected]:user/repository (push)

To push to multiple URLs do the following:

  1. Add your mirror as an extra push URL:
$ git remote set-url --add --push origin git@someinstance:user/repository
  1. Also add the original URL as a push URL. Once any pushurl exists, Git won’t use the fetch URL for pushing):
$ git remote set-url --add --push origin [email protected]:user/repository

Verify what will receive pushes:

$ git remote get-url --push --all origin

Now git push will push to both code hosting services (e.g. GitHub + your self-hosted service).

Thanks to tangled docs for the tip!