简体   繁体   中英

What is the difference between “git push origin HEAD:clean_up” and without HEAD?

What is the difference between

git push origin HEAD:clean_up

and

git push origin clean_up

What does HEAD actually mean ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM