'git push to multiple repositories simultaneously [duplicate]
How can I make git push to push not only to origin but also another remote repository?
as git push is only an alias for git push origin, can I alias git push to push to 2 remote repositories at once (with just that one command)?
I’m not looking for a non-git script here but would like to set this up for my local repository in git.
When I tried it with post-push scripts I failed.
Solution 1:[1]
No manual editing
You can add multiple URLs to a remote branch (e.g. all) directly from command line by using git config --add remote.xyz.url with different URLs:
git config --add remote.all.url ssh://user@server/repos/g0.git
git config --add remote.all.url ssh://user@server/repos/g1.git
Fully automatic
If you're super lazy and don't want to copy/paste URLs several times, this is for you:
function git-add-push-all() {
while read -r name url method; do
git config --add remote.all.url "$url"
done < <(git remote -v | awk '!/^all/ && /push/')
}
git-add-push-all # from git (sub)directory
A full bashy script is possible (test $name and $method), but awk is sweet and there is love for everyone.
Push
Then you can push to all remote with
git push all
References
Solution 2:[2]
You can also get url from configured remotes :
for repo in g0 g1 ...
do
git config --add remote.all.url `git config remote.$repo.url`
done
where g0, g1, ... are the names of your remotes.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | kcsquared |
| Solution 2 | Pierre-Olivier Vares |
