What Does "Detached HEAD" Mean in Git?
A detached HEAD means you've checked out a specific commit instead of a branch. Learn what it means, why it happens, and how to save work made in this state.
Published September 19, 2026
HEAD normally points to a branch, which in turn points to a commit. A "detached HEAD" state means HEAD is pointing directly at a specific commit instead of a branch — commonly triggered by checking out a commit hash, a tag, or a remote branch directly.
Common causes
- Running git checkout <commit-hash> or git checkout <tag> instead of a branch name
- Checking out a remote branch directly without creating a local tracking branch (git checkout origin/feature)
How to fix it
- If you just want to look around at old code, a detached HEAD is fine — just don't commit new work while in this state
- If you've already made commits in a detached HEAD state and want to keep them, create a new branch immediately with git branch new-branch-name (or git checkout -b new-branch-name)
- If you didn't mean to make changes, just check out a real branch (git checkout main) to safely leave the detached HEAD state — any uncommitted work will need to be stashed or discarded first
Example
git checkout abc1234 # detached HEAD
# ... make some commits ...
git branch save-my-work # rescue the commits onto a real branch
git checkout save-my-workFAQ
Will I lose commits made in a detached HEAD if I check out a branch?
Yes, eventually — commits not referenced by any branch become unreachable and are cleaned up by garbage collection after a while. Create a branch pointing at them before switching away if you want to keep them.