What is the difference between `checkout` and `reset`?



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 checkout and 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) master and develop are different branches of our project and (2) the HEAD pointer points to a particular branch, not a commit directly. With that, we have the following difference between the two commands:

  1. git checkout master: checkout updates HEAD. It simply makes HEAD point to the master branch instead of the develop branch as it did initially.
  2. git reset master: On the other hand, reset will move the branch that HEAD points to. That branch is updated but HEAD still 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.

FAQ: How to Backtrack - Generalizations