3

What is the difference between

git push origin HEAD:clean_up

and

git push origin clean_up

What does HEAD actually mean ?

jub0bs
  • 60,866
  • 25
  • 183
  • 186
faressoft
  • 19,053
  • 44
  • 104
  • 146

1 Answers1

2

HEAD points to the last commit of the current branch. So if the current branch be clean_up, then I would expect the following two commands to do the same thing:

git push origin HEAD:clean_up
git push origin clean_up

I can think of one scenario where you might want to use something other than HEAD when doing a git push. Suppose you checked out a certain branch branch in detached HEAD state. You made a few commits in it, and now you have decided that you want to push it out to repository as a new branch of its own. However, you want to push out the branch from one commit before the last commit you made. In this case, you would take the following steps:

git checkout <SHA-1 of `branch` you want>
# make a few commits
git push origin HEAD~1:new_branch

This would push out branch to the remote up to and including the previous commit you made.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • 2
    The main difference between the two statements is that `git push origin HEAD:clean_up` will push current local branch (with an arbitrary name) to the branch `clean_up` on origin, and `git push origin clean_up` will push a local branch named `clean_up` to a branch with the same name on origin. – joran Aug 04 '15 at 08:27