Junior Version Control

What is a detached HEAD state in Git?

A detached HEAD occurs when Git’s HEAD (which points to your current branch) points to a

specific commit instead of a branch. This means you’re not working on any branch — any

new commits made in this state are “orphaned” unless you create a branch from them.

Example:

If you check out an old commit directly:

git checkout a1b2c3d

You’re in a detached HEAD state.

If you make changes here and don’t create a new branch, you could lose them later.

Fix:

Create a new branch to save your work:

git checkout -b hotfix/rollback-test

More from Developer Essentials

All questions for this course