HEAD
The "You Are Here" Pointer
If you have 10 branches in your repository, how does Git know which one you are currently looking at? It uses a special pointer called HEAD. Notice it is fully capitalized—it is a single, unique file at the root of the `.git` directory.
A Pointer to a Pointer
Unlike branches (which point directly to a Commit Hash), the HEAD file usually points to a Branch. It says exactly: "I am currently standing on branch X".
When you type git checkout feature-branch, Git literally just rewrites the text inside the .git/HEAD file to say ref: refs/heads/feature-branch. That is the entire operation of changing branches.
Detached HEAD
You may have seen the terrifying "Detached HEAD" warning in Git. What does it actually mean?
Normally, HEAD points to a named branch (like `main`). If you make a new commit, Git moves the branch forward, and HEAD stays pointing to the branch. But if you check out a specific Commit Hash directly (e.g. git checkout 9f8a357), Git has to write that hash directly into the HEAD file instead of writing a branch name. That's it! "Detached HEAD" just means the HEAD file contains a raw hash instead of a branch reference.
Why is it dangerous?
If you are in a Detached HEAD state and make a new Commit, Git creates the Commit... but no branch is pointing to it! If you checkout another branch, that new Commit becomes "abandoned" (unreachable by any bookmark) and will eventually be permanently deleted by Git's garbage collection.
Proving the Architecture
Let's view the literal contents of the HEAD file on a normal branch, and then see what happens when we detach it.