Reputation: 181
I have been using this command for a while for pushing my code in Gerrit..
git push origin HEAD:refs/for/branch
However, recently I am working on an infrastructure which doesn't have a Gerrit pipeline. I could do a push, but I wasn't able to see the branch on git. When I run:
git push origin branch
it can be seen on git. I am trying this on a new branch, which I created locally.
Upvotes: 1
Views: 6230
Reputation: 22321
The command git push works like the following:
git push REPOSITORY SOURCE_REFSPEC:DESTINATION_REFSPEC
With Gerrit, when you use:
git push origin HEAD:refs/for/branch
You're asking Git to:
Push to the origin repository (by default, the repository you have cloned from)
Push the current commit of your working tree
Push the commit to "branch" to be reviewed on Gerrit. The "refs/for/" prefix is a "magical" branch which "instruct" Gerrit that a Code Review must be created. See more info about this here.
The "refs/for/" prefix only makes sense if you're working with Gerrit.
Finally, if you're not working with Gerrit and execute "git push origin branch" you're pushing your current commit to the "branch" branch on "origin" repository.
Upvotes: 7