A detached HEAD state happens when Git's HEAD points directly to a specific commit instead of to a branch, meaning any new commits you make aren't attached to any branch and can be lost if you switch away carelessly.
A developer runs git checkout a1b2c3d to inspect an old commit, makes a small fix, and forgets they're in detached HEAD; without creating a branch first, switching back to main would leave that fix orphaned and eventually eligible for garbage collection.
git checkout a1b2c3d
# realize you need to keep changes made here
git checkout -b rescue-branchA concise interview answer is
Detached HEAD happens when you check out a specific commit or tag instead of a branch, so HEAD points directly at that commit rather than moving with a branch. Any commits made there aren't attached to a branch, so I always create a new branch first if I need to keep that work.
Last updated: 11 November 2026
Previous question: A teammate pushes a commit that breaks the build. What steps would you take?
Next question: How can you use Git to implement feature toggles in a codebase?