Skip to main content

HEAD

Pronunciation
HED
Updated 2 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/git-head

In short

HEAD is Git's pointer to what you have checked out, normally the current branch, which points to its latest commit; new commits are added where HEAD points.

What is HEAD in Git?

Git stores HEAD in the file .git/HEAD. Most of the time it contains a reference to a branch, such as ref: refs/heads/main, so HEAD means "the tip of the branch I'm on". When you commit, the branch moves forward to the new commit and HEAD moves with it, because it follows the branch.

HEAD is also the starting point for relative references. HEAD~1 is the parent of the current commit, HEAD~3 three commits back, and HEAD^2 the second parent of a merge commit. Commands use it everywhere: git diff HEAD shows all changes since the last commit, git reset --soft HEAD~1 undoes the last commit but keeps its changes staged, and git show HEAD displays the latest commit.

If you check out a commit, tag or remote branch directly instead of a local branch, HEAD points straight at a commit. That is a detached HEAD: you can look around and even commit, but those commits belong to no branch and are easy to lose, so create a branch with git switch -c if you want to keep them.

A common misconception is that HEAD always means the latest commit in the repository. It is only where you are right now. Git also keeps related markers, such as ORIG_HEAD, set before risky operations like reset and rebase so you can go back, and FETCH_HEAD, which records what the last fetch brought in.

Key takeaways

  • HEAD points to what is checked out, normally the current branch.
  • New commits are added where HEAD points, moving the branch forward.
  • HEAD~1, HEAD~3 and HEAD^2 refer to commits relative to it.
  • Pointing HEAD directly at a commit gives a detached HEAD.
  • ORIG_HEAD and FETCH_HEAD are related markers Git sets automatically.

Example

Looking at and using HEADbash
cat .git/HEAD
# ref: refs/heads/main          ← HEAD follows the main branch

git log --oneline -3
# 9f2c1ab (HEAD -> main) Add search
# 41d0e77 Fix login redirect
# c83b5a2 Initial commit

git show HEAD~1 --stat          # the commit before the latest
git diff HEAD                   # everything changed since the last commit
git reset --soft HEAD~1         # undo the last commit, keep its changes staged

Readers ask

What does HEAD~1 mean?

The parent of the commit HEAD points to, one step back in history. HEAD~2 is two steps back, and so on. For merge commits with two parents, HEAD^2 selects the second parent.

What is a detached HEAD?

A state where HEAD points directly to a commit instead of to a branch, for example after checking out a tag or an old commit. Commits made there are not on any branch until you create one.

What is the difference between HEAD and main?

main is a branch: a pointer to a commit. HEAD points to the branch you are currently on. When you are on main they refer to the same commit, but after switching branches HEAD points to the new branch.

See also

Spotted a mistake or something missing on this page?Suggest an edit

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings