Pushing to all git remotes with one command
Tags: howtos
Published on
« Previous post: A new position
— Next post: LaTeX Templates for Theses and Reports »
If you are like me and a long-term git
user, you will probably
accumulate numerous remotes per repository (maybe one for
your private server, one for work, and so on).
Pushing to all of them can get a bit tedious, so I defined a new
commnad gpa
, which is of course short for git push all
:
git remote | xargs -L1 git push --all
Let us dissect this quickly:
- The need for
git remote
is obvious because it permits us to enumerate all remotes - We need
xargs -L1
in order to format the input to fit into one line - Finally, the
git push --all
pushes all branches to the specified remote
I have alias gpa='git remote | xargs -L1 git push --all'
in my ZSH
configuration, so that I can use this command globally.
Happy committing, until next time!
Update: Conrad was kind enough to
point out that one can just as well modify .gitconfig
accordingly and
make this command an alias of the git
command:
[alias]
pushall = !git remote | xargs -L1 git push --all
Thanks!