What Does HEAD Mean in Git?
In Git, HEAD tells you what your repository currently has checked out. Most of the time it refers to your current branch, which in turn points to a commit. This guide explains that relationship, shows what changes in detached HEAD state, and decodes references like HEAD~1.
What is HEAD in Git?
HEADis Git's reference to the current checkout. In the usual case, HEAD refers to a local branch, and that branch refers to its latest commit. When you create a commit on that branch, Git advances the branch reference; HEAD continues to identify the checked-out branch.
HEAD -> main -> a1b2c3d (latest commit on main)The diagram is conceptual. A normal branch reference stores a commit ID, while HEAD is commonly a symbolic reference to that branch.
How to see what HEAD refers to
Run git status to see your current branch and working tree state. To print the branch name directly, use:
git branch --show-currentTo see the commit identified by HEAD, use git log -1 --oneline. The special name HEAD can also be used anywhere Git expects a commit reference, for example git show HEAD.
What does detached HEAD mean?
You are in a detached HEAD state when HEAD points directly to a commit instead of to a local branch. This commonly happens when you check out a specific commit or a remote-tracking reference. You can inspect files and even make commits, but new commits are not attached to a branch unless you create one.
git switch --detach <commit>If you make a commit you want to keep, create a branch at that commit before switching away:
git switch -c save-my-workIf you only checked out a commit to inspect it, return to a branch with git switch <branch-name>. Learn more in the guide to fixing detached HEAD.
What do HEAD~1 and HEAD^ mean?
Git lets you describe commits relative to another commit. HEAD~1 means the first parent of the current commit. HEAD~2means the first parent's first parent, two steps back along the first-parent chain.
git show HEAD~1
git log -1 --oneline HEAD~2HEAD^ is shorthand for the first parent, so HEAD^ and HEAD~1 refer to the same parent. For a merge commit, HEAD^2 refers to the second parent; HEAD~2 still follows the first parent twice. These are ways to name commits, not commands that change your repository.
Does HEAD move when you make changes?
Editing files does not move HEAD. Changes remain in the working tree until you stage and commit them. When you create a commit while on a branch, Git advances that branch to the new commit; HEAD remains attached to the branch.
- Edit a tracked file;
HEADstill identifies the current checkout. - Stage the change with
git add <file>. - Create a commit with
git commit. - The current branch advances to the new commit.
HEAD vs. a branch name
HEADidentifies the current checkout.- A branch name such as
mainidentifies the latest commit on that branch. - When you switch branches,
HEADfollows the branch you checked out. - When you switch to a commit directly,
HEADis detached from a branch.
Git HEAD FAQ
Is HEAD a branch?
Not exactly. In a normal checkout, HEAD is a symbolic reference to the current branch. In detached HEAD state, it points directly to a commit.
What does HEAD~ mean without a number?
HEAD~ is equivalent to HEAD~1: the first parent of the current commit.
Does HEAD always point to the latest commit in the repository?
No. It identifies the commit or branch currently checked out, which may not be the newest commit on another branch or the newest commit fetched from a remote.