Gitflow
🚚Stash Is on the Wrong BranchMedium+500 XP
Scenario reference

Stash Is on the Wrong Branch: the situation, step by step

The situation

You stashed WIP while on `main`. It was actually feature work. You want it on a new branch instead.

Create the branch you meant to be on, switch to it, then pop the stash there.

Medium · 3 steps · +500 XP

What you will practice

This scenario walks through 3 steps, in order:

  1. 01Confirm the stash exists
  2. 02Create and switch to the branch the work belongs on
  3. 03Pop the stash onto the new branch
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. Confirm the stash exists
    git stash list
  2. 2. Create and switch to the branch the work belongs on
    git switch -c feature/from-stash
  3. 3. Pop the stash onto the new branch
    git stash pop

Key takeaway

`git stash branch <name>` bundles these two moves into one command — it branches from the commit the stash was taken on, then pops. Doing it by hand is switch + pop.