I’ve just started using gerrit and I want to know why we need to do git push gerrit HEAD:refs/for/master instead of doing git push origin master
If I do git push origin master I get the error saying ! [remote rejected] master -> master (prohibited by Gerrit)
The documentation for Gerrit, in particular the “Push changes” section, explains that you push to the “magical
refs/for/'branch'ref using any Git client tool”.The following image is taken from the Intro to Gerrit. When you push to Gerrit, you do
git push gerrit HEAD:refs/for/<BRANCH>. This pushes your changes to the staging area (in the diagram, “Pending Changes”). Gerrit doesn’t actually have a branch called<BRANCH>; it lies to the git client.Internally, Gerrit has its own implementation for the Git and SSH stacks. This allows it to provide the “magical”
refs/for/<BRANCH>refs.After a successful patch (i.e, the patch has been pushed to Gerrit, [putting it into the “Pending Changes” staging area], reviewed, and the review has passed), Gerrit pushes the change from the “Pending Changes” into the “Authoritative Repository”, calculating which branch to push it into based on the magic it did when you pushed to
refs/for/<BRANCH>. This way, successfully reviewed patches can be pulled directly from the correct branches of theAuthoritative Repository.