Skip to content

Detached HEAD

Easy — everyone uses thisGit & Version Control

ELI5 - The Vibe Check

Detached HEAD is the state you end up in when you check out a specific commit instead of a branch, and git politely warns you that anything you commit here won't belong to any branch. It's like stepping off the trail to look at something interesting, totally fine to look around, but if you start building something there and then wander back to the trail, whatever you built gets left behind and can vanish.

Real Talk

Detached HEAD occurs when HEAD points directly to a commit hash rather than to a branch reference, typically after checking out a specific commit, tag, or the result of a bisect. Any new commits made in this state are not attached to any branch and become unreachable, and thus eligible for garbage collection, the moment you check out a branch, unless you first create a new branch pointing at them with git switch -c or git branch.

Show Me The Code

$ git checkout a1b2c3d
Note: switching to 'a1b2c3d'.
You are in 'detached HEAD' state...
$ git switch -c rescue-branch

When You'll Hear This

"You're in detached HEAD, make a branch before you commit anything else." / "I lost an afternoon of work because I forgot I was in detached HEAD."

Made with passive-aggressive love by manoga.digital. Powered by Claude.