Skip to content

HEAD

In one line

HEAD is a pointer to the currently checked-out commit — it tells Git where you are in the history.

In simple words

HEAD is Git's way of knowing "where you are right now." It points to the commit you currently have checked out. When you make a new commit, Git creates it as a child of HEAD and moves HEAD to the new commit.

HEAD usually points to a branch name (like main), and the branch points to a commit. So HEAD → branch → commit. When you switch branches, HEAD updates to point to the new branch.

You can also put HEAD in a "detached" state by checking out a specific commit hash or tag directly. In that state, HEAD points to a commit instead of a branch, and any commits you make will not belong to any branch — they could be lost if you switch away without creating a branch.

Example

bash
# See what HEAD points to
cat .git/HEAD
# Usually shows: ref: refs/heads/main

# HEAD~1 means one commit before HEAD
git reset HEAD~1

# Detach HEAD by checking out a commit
git checkout abc123  # HEAD now points to abc123 directly

HEAD normally points to a branch ref. Checking out a commit detaches HEAD.

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary