What is the HEAD in git?

e-satis picture e-satis · Mar 27, 2010 · Viewed 91.2k times · Source

There seems to be a difference between the last commit, the HEAD and the state of the file I can see in my directory.

What is HEAD, what can I do with it and what mistake should I avoid?

Answer

poke picture poke · Mar 27, 2010

HEAD is a reference to the last commit in the currently checked-out branch.


There is a small exception to this, which is the detached HEAD. A detached HEAD is the situation you end up in whenever you check out a commit (or tag) instead of a branch. In this case, you have to imagine this as a temporary branch without a name; so instead of having a named branch reference, we only have HEAD. It will still allow you to make commits (which will update HEAD), so the above short definition is still true if you think of a detached HEAD as a temporary branch without a name.