Git Developer Guide

Git detached HEAD: what it means and how to fix it

Why does Git say "You are in 'detached HEAD' state"?

In normal operation, Git's HEAD pointer refers to a branch name (like main), which in turn points to the latest commit. When you check out a specific commit hash, tag, or remote branch directly (or pause during an interactive rebase or bisect), HEAD points directly to that commit SHA. Any new commits made here are not attached to any branch and can easily be lost during a later checkout.

How to fix it

Scenario A: You made commits and want to save them

Create a new branch right where you are:

# Creates and switches to a new branch preserving your commits
git switch -c my-saved-work

Scenario B: You just want to return to your normal branch

If you made no commits (or don't want any experimental changes), simply switch back to your branch:

git switch main
# or git checkout main

How GitMon helps

It is easy to leave a repository in a detached HEAD state without noticing. GitMon actively monitors your repositories and displays a high-visibility badge whenever any repository is detached, so you can resolve it before switching tasks.

Download GitMon Free Trial Learn more

Related Guides