I often find myself typing this:
git push remote1 branch1 branch2 tag1 tag2 tag3..
git push remote2 branch1 branch2 tag1 tag2 tag3..
I would prefer an alias where I can type this instead:
git pushall branch1 branch2 tag1 tag2 tag3 ..
Note: I am aware I could create a new remote "all" with multiple urls. Let's not discuss this here, but focus on the alias instead!
I am ok to hardcode the remote names, because I have a number of projects with the same multiple remote names (usually "drupal" and "github").
Progress so far
I already figured out a non-variadic version:
[alias]
pushall = "!git push github $1; git push drupal $1; #"
Two tricks here were
- using double quotes to prevent ';' from having a special meaning in
.ini
files #
to ignore the rest of the line.
But this only pushes one branch (or tag) at a time. So I would have to type this:
git pushall branch1
git pushall branch2
git pushall tag1
git pushall tag2
git pushall tag3
...
I would prefer an alias where I can type this:
git pushall branch1 branch2 tag1 tag2 tag3 ..
Why not a new remote "all" with multiple push urls?
As said, let's focus on the aliases, so that readers find what they are looking for.
Anyway, here is why I am not creating a remote "all":
- I would have to do this once per project, and could not do it globally. In my case, hardcoding the remote names in a global alias is actually fine!
- Afaik, I would pollute my history with refs like "all/branch1" instead of or in addition to "remote1/branch1" and "remote2/branch1".
The correct place to discuss this would be here, pull/push from multiple remote locations
See also
The following are related, but they do not address variadic parameters:
- Git Alias - Multiple Commands and Parameters
- Syntax for Git aliases with multiple commands
- Git alias with positional parameters
The following might be helpful, but it addresses pure shell script, not specifically git aliases:
Just for the record, the following "cheat" does work. It is not really a complete answer but it might be good enough for many.
Yes this is not truly variadic, because it is limited to 5 parameters (or whichever number you choose when creating the alias). Also it cannot pass options like
--key=value
. But as said it might be just good enough for you.In my specific use case, most of the time I just push one branch and one release tag, so two parameters (
$1 $2
) would be enough.Note that
:
at the end seems to have the same effect as#
. I learned this somewhere else here on stackoverflow.I will not "accept" this answer, because I want to leave the opportunity for someone to come up with something better.