git push to multiple repositories

Wolfgang Klinger
1 min readSep 20, 2019

--

Did you know that it’s possible to push to multiple git repositories at once without any additional (server) software?

This is especially useful if your client has a repository and you want to keep a copy on your own server (e.g. if you use a bug tracker like Redmine or Jira that’s using the commit messages to track changes).

Use this command to add another pushurl for your remote (in this example origin).

git remote set-url --add --push origin ssh://git@myserver.com/myrepository.git
git remote set-url --add --push origin ssh://git@myserver2.com/myrepository2.git

This will result in the following changes in your .git/config file.

[remote "origin"]
url = ssh://git@myserver.com/myrepository.git
fetch = +refs/heads/*:refs/remotes/origin/*
pushurl = ssh://git@myserver.com/myrepository.git
pushurl = ssh://git@myserver2.com/myrepository2.git

You can verify the result with:

$ git remote show origin|head -n4
* remote origin
Fetch URL: ssh://git@myserver.com/myrepository.git
Push URL: ssh://git@myserver.com/myrepository.git
Push URL: ssh://git@myserver2.com/myrepository2.git

Keep in mind that the push will occur in the given order and if one push fails, the others are not executed!

Reference:
https://git-scm.com/docs/git-push#_remotes_a_id_remotes_a

--

--

Wolfgang Klinger
Wolfgang Klinger

Written by Wolfgang Klinger

Programmer, Photographer, Gardener

No responses yet