Kaustav Sarkar
Kaustav Sarkar

Reputation: 181

What happens when git push origin HEAD:refs/for/branch

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

Answers (1)

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:

  • REPOSITORY=origin

Push to the origin repository (by default, the repository you have cloned from)

  • SOURCE_REFSPEC=HEAD

Push the current commit of your working tree

  • DESTINATION_REFSPEC=refs/for/branch

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

Related Questions