Pushing changes to Gerrit requires the rather esoteric command
git push origin HEAD:refs/for/branchname
We've scripted this, but I'm looking for a way to do this natively. With git's powerful config, it looks like I can preconfigure most of it[1] so that just git push
suffices... almost. I'm stuck on the remote.<name>.push
refspec.
I can already create a tracking topic branch so that git pull
(no other parameters) will pull changes from upstream remote into my topic branch. However with Gerrit, the push and fetch refspecs aren't the same: one fetches (merges) from refs/heads/trackbranch
, but one pushes to refs/for/trackbranch
[2]
I can configure a push
refspec in remote.<name>.push
, however the syntax is pretty basic: if I put
push = refs/heads/*:refs/for/*
Then that will try pushing my t-foo
topic branch to refs/for/t-foo
. But git has the information that t-foo
is tracking trackbranch
. Can I define a refspec so that git automatically tries to push any t-foo
to its refs/for/trackbranch
?
We're currently using a script to do this, and I suppose I could define a push refspec for each topic branch (possibly through more scripting). I'm hoping there's a native git way of doing this so that we don't need to rely on more custom in-house scripts for our team.
[1] by defining a tracking branch with git checkout origin/upstream_branch -b topic_branch
or within an existing branch git branch --set-upstream-to origin/upstream_branch
[2] pushing to refs/for/*
creates a changeset for review. With appropriate permissions, one could push to refs/heads/*
to bypass review, but that negates most of the point of Gerrit.