detached HEAD

The state where HEAD holds a commit ID directly instead of a branch name, so new commits are made but no branch moves to follow them.

Commits made while detached are easy to lose once you switch away.

In more detail

It happens when you switch to a commit, tag or remote-tracking branch, and it is a normal state for looking around, not an error. Commits made while detached are kept only as long as something points at them, so Git warns you when you leave. To keep them, create a branch with git switch -c before or after leaving.

Example

git switch --detach HEAD~1

Related terms

Taught in

References