Can I set push-options (git push -o "...") in git config?

2.5k views Asked by At

Git 2.10 introduced git push options (git push -o "my string").

Many command line options are configurable, and I was wondering if it was possible for this too. I was not able to find it in git-config, but perhaps I'm overlooking it.

So, would it be possible to add a (set of) default push option(s), to have ...

git push -o "r=joh.doe"

... the default when running ...

git push

?

Context: I am using this with Gerrit to directly assign changes to reviewers (documentation for reference - using compatible syntax <push-ref>%my_string). When uploading many changes and working in pairs to review each other's code it would be useful if I can add that person as reviewer at push-time already.

3

There are 3 answers

0
gertvdijk On BEST ANSWER

This has become configurable in Git 2.16 (quoting release notes).

The "--push-option=" option to "git push" now defaults to a list of strings configured via push.pushOption variable.

So, when applied to Gerrit as for my use case, this should work to add reviewer to john.doe and publish draft comments on push time by default.

git config --add push.pushOption r=john.doe
git config --add push.pushOption publish-comments
1
Marcelo Ávila de Oliveira On

What if you just define some aliases to do that?

Ex:

alias gp-doe='git push -o "r=joh.doe"'

You can use Git Aliases too.

2
ElpieKay On

This option is not configurable.

You can add the reviewer by Gerrit's CLI ssh -p 29418 $USER@$gerrithost gerrit set-reviewers $CHANGE -a $reviewer -p $project in Gerrit's hook patchset-created. The REST API POST /changes/{change-id}/reviewers can also do the job.

$reviewer can be a user or a group which contains one or more users.