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:
- Add your mirror as an extra push URL:
$ git remote set-url --add --push origin git@someinstance:user/repository
- Also add the original URL as a push URL. Once any
pushurlexists, 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!