← Back to all fixes
Stuck in detached HEAD state
The Issue
`git status` shows "HEAD detached at abc1234". Commits you make seem to vanish.
Root Cause
You checked out a specific commit hash or tag instead of a branch. Git is now not on any branch — commits are made but not reachable via any branch name.
How to Fix
To go back to a branch: `git checkout main` (or master/your branch name)To save your work: create a branch from the detached state: `git checkout -b my-work`To see what HEAD is: `git log --oneline -5`Commits in detached HEAD are not lost immediately — git gc will clean them up after 30 days