What is HEAD

HEAD is the ref that tells Git where you are right now. It is stored in .git/HEAD and typically contains a symbolic reference to the current branch:

ref: refs/heads/main

How it works

When you commit, Git reads HEAD to find the current branch, creates the new commit with the branch's current commit as parent, and advances the branch ref to the new commit. HEAD itself does not change — it still points to the branch name.

git checkout feature changes HEAD to ref: refs/heads/feature. git checkout main changes it back. The working tree is updated to match the commit that the new branch points to.

HEAD can also point directly to a commit hash instead of a branch name — this is detached HEAD state. Commits made in this state are not on any branch.

Common shorthands: HEAD~1 means the parent of HEAD, HEAD~2 means the grandparent, HEAD^2 means the second parent of a merge commit.

Why it matters

HEAD is the anchor for almost every Git command. git diff compares against HEAD. git log starts from HEAD. git reset moves the branch that HEAD points to. Understanding HEAD is essential for understanding what Git commands will do.

See How Git Branching Works for the complete explanation of HEAD and refs.