← Back to all fixes
Git

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
  1. To go back to a branch: `git checkout main` (or master/your branch name)
  2. To save your work: create a branch from the detached state: `git checkout -b my-work`
  3. To see what HEAD is: `git log --oneline -5`
  4. Commits in detached HEAD are not lost immediately — git gc will clean them up after 30 days