Folusho Oladipo
2 min readMay 20, 2016

What is the HEAD of a Git repository and what is its importance?

HEAD is a reference to the last commit in the currently checked-out branch. It applies to the current branch of any Git repository, and keeps track of the most recent commit.

When do you get to use the HEAD? The most common use for the HEAD is undoing your most recent commit. Say you were testing out some code but were not ‘in the zone’ enough to write bug-free, efficient code. If you do commit this bomb, you’ll need to undo your commit, right? So, in comes HEAD. You can easily revert that commit with:


git reset HEAD

This undoes the last commit, unstages BUT doesn’t revert the changes you made to your files. So, now HEAD refers to two commits back instead of the last commit. However, if you want to undo BOTH the commit AND the changes you made to your files, use:


git reset --hard HEAD

Note that this will affect ALL files changed in your last commit, not just one. So use with caution.

Another use case is when you ‘git checkout’ into a tag, a remote branch or a specific commit instead of a local branch. Running ‘git status’ at this point will, among other things, say you’re in a ‘detached HEAD’ state. Think of it as being in a temporary branch that has a HEAD. The difference is that A detached HEAD doesn’t have a named branch, hence it is described as being ‘detached’.

For further details about HEAD, you can check this link: http://stackoverflow.com/questions/2529971/what-is-the-head-in-git

Watch out for my next highly informative article. In the meantime, keep your HEAD up!