My team is using gerrit code review, essentially this means the default push behaviour bypasses the standard workflow so instead we need to use git push origin HEAD:refs/for/feature
to correctly push our code to get reviewed.
The default push behaviour looks like this:
user$ git push --dry-run
To https://gerrit.company.url/project
83fa2a5..aca3a22 feature -> feature
This would bypass the review process which is undesired.
When I set the push ref-spec (reference here) to be refs/heads/*:refs/for/*
this takes a step in the right direction:
user $ git config remote.origin.push refs/heads/*:refs/for/*
user$ git push --dry-run
To https://gerrit.company.url/project
* [new branch] master -> refs/for/master
* [new branch] old_stuff -> refs/for/old_stuff
* [new branch] feature -> refs/for/feature
Now it is trying to push feature
to refs/for/feature
which is what I want but it's also trying to push all my branches to origin. Gerrit rejects more than one request so I get an output like this:
user$ git push
....
To https://gerrit.company.url/project
! [remote rejected] master -> refs/for/master (no new changes)
! [remote rejected] old_stuff -> refs/for/old_stuff (duplicate request)
! [remote rejected] feature -> refs/for/feature (duplicate request)
but I found that if I name the current branch it does what I'm expecting:
user $ git push origin feature --dry-run
To https://gerrit.company.url/project
* [new branch] feature -> refs/for/feature
This is great and I will be able to use this but I'd like to narrow it more. I figured if I set push.default
to current
it will mean that git push
will only push the current branch in this way, but to my disappointment:
user$ git config push.default current
user$ git push origin --dry-run
To https://gerrit.company.url/project
* [new branch] master -> refs/for/master
* [new branch] old_stuff -> refs/for/old_stuff
* [new branch] feature -> refs/for/feature
This seems to be ignoring the push.default
setting, From the git config documentation:
push.default
Defines the action
git push
should take if no refspec is explicitly given
So the remote.origin.push
config gets interpreted as an explicit ref spec? Even when setting the default push behaviour to nothing
it still tries to push all branches:
user$ git config push.default nothing
user$ git push
fatal: You didn't specify any refspecs to push, and push.default is "nothing".
user$ git config remote.origin.push refs/heads/*:refs/for/*
user$ git push origin --dry-run
To https://gerrit.company.url/project
* [new branch] master -> refs/for/master
* [new branch] old_stuff -> refs/for/old_stuff
* [new branch] feature -> refs/for/feature
What am I missing here? How do I get git push
to only push the current branch like feature -> refs/for/feature
?
remote.origin.push
is defined then it doesn't make any difference whatpush.default
is set to, I demonstrate that in the last example. – Autocrat