The behavior of
git reset and
git checkout seem similar in the way that they treat the
HEAD pointer and the commits that we have access to as a result. How do they differ?
The differences in the way that
reset treat the
HEAD pointer can be a bit subtle. The following image from ProGit Git reference book is very helpful.
So what are we seeing here? First, let’s understand that (1)
developare different branches of our project and (2) the
HEADpointer points to a particular branch, not a commit directly. With that, we have the following difference between the two commands:
git checkout master:
HEAD. It simply makes
HEADpoint to the
masterbranch instead of the
developbranch as it did initially.
git reset master: On the other hand,
resetwill move the branch that
HEADpoints to. That branch is updated but
HEADstill points to the same branch.
So although the commit that the
HEAD pointer is referring to is the same, the way that the commands behave are quite different.