What is a detached HEAD state?medium

Type
conceptual
Topic
git-internals
Frequency
occasional
Tags
git, internals
Answer

HEAD points directly to a commit SHA instead of a branch name. Any commits made here are not reachable from any branch and may be garbage collected.

Explanation

This happens when you check out a specific commit, tag, or remote branch. To keep work done in detached HEAD, create a new branch before leaving: git switch -c new-branch .

Follow-upHow do you recover commits made in a detached HEAD state?