Gitflow
🪖Commits in Detached HEADMedium+500 XP
Workshop
Scenario reference

Commits in Detached HEAD: the situation, step by step

The situation

You ran `git checkout <hash>` to look at an old version, then 'just made a quick fix' and committed. Now Git warns about leaving the commit behind.

Detached HEAD commits are orphans until you branch from them.

Medium · 3 steps · +500 XP

What you will practice

This scenario walks through 3 steps, in order:

  1. 01Check out an older commit (detaches HEAD)
  2. 02Create a branch to save the work
  3. 03Confirm with log
Reveal the step-by-step commands

Try the terminal first — you learn more by doing. When you want to check yourself, here is the command for each step.

  1. 1. Check out an older commit (detaches HEAD)
    git checkout dd00001
  2. 2. Create a branch to save the work
    git switch -c rescue-branch
  3. 3. Confirm with log
    git log --oneline

Key takeaway

Always `git switch -c <name>` before committing in detached HEAD.