Detached HEAD
In one line
Detached HEAD means HEAD points directly to a commit instead of a branch — commits you make will not belong to any branch and could be lost.
In simple words
Normally, HEAD points to a branch name, and the branch points to a commit. When you git checkout <commit-hash> or git checkout <tag>, HEAD points directly to the commit — this is "detached HEAD."
In detached HEAD state, you can view and even edit files, but any commits you make will not belong to any branch. If you switch to another branch, those commits become unreachable and may be garbage collected (lost permanently).
To save commits made in detached HEAD, create a branch from the current position: git branch <name> then git checkout <name>. Or use git checkout -b <name> to create and switch in one step. If you have not committed anything, just git checkout <branch> to return to normal.
Example
# Detach HEAD by checking out a commit
git checkout abc123
# HEAD is now at abc123 (detached)
# Save commits made in detached state
git checkout -b fix-from-abc123
# Or just return to a branch if no commits were made
git checkout mainChecking out a commit detaches HEAD. Create a branch to save any commits.
Related terms
Related Resources
Related Lessons
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.