Skip to content
BENIBIX Learn

Git HEAD

Development🔀 Version ControlBranches and History

Also known as HEAD, Detached HEAD

Git's mark for where you are now: your branch and your commit.

Think of it like

Think of it like a you are here pin on a map. It shows where you stand right now.

Example

Jack switches from main to search. HEAD now points at search, so his next commit lands on that branch.

Why it matters

Every Git command acts on where HEAD is. Knowing it stops commits from landing in the wrong place.

Definition

HEAD is Git's name for the commit you are on right now. Most of the time it points to a branch, and that branch points to its latest commit. When you switch branches, HEAD moves with you. If you check out an old commit directly, HEAD points at that commit alone, which Git calls a detached HEAD. New commits made there can get lost if you do not put them on a branch.

Example code

console
$ cat .git/HEAD
ref: refs/heads/main
HEAD is a tiny file that names the branch you are on.

Common mistake

Making commits in a detached HEAD and then switching away. They are left with no branch and are easy to lose.

Key takeaways

  1. 1
    You are here. It marks your current commit.
  2. 2
    Moves with you. Switching branch moves HEAD.
  3. 3
    Detached is risky. Make a branch before you commit.

Learn it properly