Entering Detached HEAD
git checkout <commit-hash>
HEAD now points directly at that real commit, not at any branch. git warns about this on the real terminal, but nothing is actually wrong yet.
Real Work, No Branch Following It
Real, genuine commits — they exist on disk exactly like any other. No branch pointer moves with them, though.
The Real Escape
git switch master
git switch -c rescued-work HEAD@{1}
HEAD@{1}, run right after switching away, is exactly the tip of the detached work. A genuinely new branch there keeps every real commit safe.
Checking out a specific real commit hash directly — instead of a branch name — genuinely detaches HEAD: it now points straight at that commit, not at any branch. New real commits made from here still get made, completely normally, but no branch pointer follows along.
Switching to a real branch afterward leaves those detached commits referenced by nothing but reflog — still real, still on disk, but one real garbage collection away from disappearing for good. Creating a genuine new branch at that exact point, before switching away (or immediately after, via reflog), is the standard, real escape plan.
Detached HEAD
A real, valid git state where HEAD points directly at a commit instead of a branch. Confirmed directly in this lab: commits made there are completely real and functional, they simply have no branch pointer following them.
git switch -c <branch> <ref>
Creates a genuinely new branch at any real ref — including a reflog reference like HEAD@{1} — and switches to it in one step. Confirmed directly in this lab: it captured all three real detached commits onto a new, permanent branch pointer.
Takeaways
- git checkout <hash> genuinely detaches HEAD — it points at a commit directly, not a branch
- Commits made while detached are completely real, but no branch pointer follows them
- Switching to a real branch afterward leaves those commits reachable only through reflog
- git switch -c <name> HEAD@{1}, run right after switching away, rescues them onto a genuinely permanent branch