Gitflow
😬Committed to Wrong Branch!Easy+350 XP
Workshop
Scenario reference

Committed to Wrong Branch!: the situation, step by step

The situation

You made 2 commits directly on `main` instead of a feature branch. CI failing, team lead pinging.

The commits are good — just need to move them to feature/payments.

Easy · 4 steps · +350 XP

What you will practice

This scenario walks through 4 steps, in order:

  1. 01Create branch to save commits
  2. 02Reset main back 2 commits
  3. 03Switch to feature branch
  4. 04Verify commits
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. Create branch to save commits
    git branch feature/payments
  2. 2. Reset main back 2 commits
    git reset --hard HEAD~2
  3. 3. Switch to feature branch
    git switch feature/payments
  4. 4. Verify commits
    git log --oneline

Key takeaway

Branch before reset = nothing lost. This happens daily.