I like to keep my default push strategy on current
but every now and then I need to modify multiple branches and then push all of them i.e. I need to do a push with the strategy set to matching
.
When done branch by branch it generates a lot of noise and takes time. The other option I have is to temporarily set my push strategy for that repository, do the push and then set it back to my default. This got me wondering is there a way to specify push strategy for a single push similar to the git merge strategies?
Note: I am aware of the push option --all
but I also have local branches not meant to be pushed.
I assume by "push strategy" you mean the setting of push.default
(which goes with current
and matching
).
To run one Git command while overriding the configuration setting of some Git configuration variable(s) for the duration of that one command, use:
git -c <name>=<value> command
e.g., git -c push.default=matching push
.
Note, however, that push.default
affects only a git push
that does not list refspecs on the command line. For scripting purposes it's probably wiser, in general, to construct the set of refspecs that you do intend to push, then pass them as arguments:
pushargs=
for b in ...; do
if want-to-push $b; then
pushargs="$pushargs $b"
fi
done
if [ -n "$pushargs" ]; then git push $remote $pushargs; fi
for instance (assuming $remote
is already set and the ...
part has some obvious way to fill it in). In addition, if you mean matching
, the special refspec :
means that:
git push origin :
for instance.