What is a detached HEAD in Git?

Normally HEAD points to a branch. When you check out a commit, a tag or a remote branch directly, HEAD points to that commit. This is the detached HEAD state.

Terminal output

$ git switch –detach HEAD~1
HEAD is now at 0057196 First
$ git status
HEAD detached at 0057196
nothing to commit, working tree clean

You can look around, but new commits there belong to no branch, and Git may delete them later. To keep them, create a branch: git switch -c new-branch. To leave, use git switch main.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.