Suppose I have 5 local commits. I want to push only 2 of them to a centralized repo (using an SVN-style workflow). How do I do this?
This did not work:
<
By default, git-push pushes all branches. When you do this:
git checkout HEAD~3 #set head to three commits ago
git push #attempt push from that head
You move to a detached HEAD (you're not on any branch) and then you push all the branches, including the local master (which is still where it was) to the remote master.
The manual solution is:
git push origin HEAD:master
If you find the default behaviour of pushing all branches confusing (and dangerous!), add this to your ~/.gitconfig:
[remote.origin]
push = HEAD
Then only the branch you're on is pushed. In your example (a detached head), you would have got this error message, rather than accidentally pushing the wrong commits:
error: unable to push to unqualified destination: HEAD