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:
$@
means variadic arguments in shell script, and this also works for git aliases. I was not aware of this. Now I don't know which of those answers I should accept.. I will see. – Corroboree