Detached HEAD

A detached HEAD occurs when HEAD points directly to a commit rather than to a branch reference. This is normal when inspecting historical commits or checking out tags. You can make temporary commits in this state, but those commits may become difficult to reach after switching away unless you create a branch.

Recover Work from Detached HEAD
git switch --detach abc1234
# make changes and commit

git switch -c experiment
git log --oneline --decorate
💡 Creating a branch while detached gives the new commits a named reference so they remain easy to find.
Key Takeaways
  • Detached HEAD is not automatically an error.
  • It is common when inspecting commits and tags.
  • Create a branch if you want to preserve new commits made there.
Knowledge Check

What does detached HEAD mean?