Apply vs Pop
Once you've stashed something, there are two ways to bring it back: git stash apply and git stash pop. They look almost identical, but they differ in one important way — whether the stash stays on the stack afterwards. Choosing the right one is the difference between a confident restore and an accidentally lost change.
The one-line distinction
apply= restore the changes, keep the stash on the stack.pop= restore the changes, and drop the stash if (and only if) the restore succeeded cleanly.
The defaults
No argument = stash@{0}
git stash apply # apply stash@{0}, leave it on the stack
git stash pop # apply stash@{0}, then drop it if cleanTargeting a specific stash
Any index works
git stash apply stash@{2}
git stash pop stash@{2}
# Bare numbers also work in modern Git
git stash pop 2Apply vs pop — when to choose which
Situation | Use | Why |
|---|---|---|
You're unsure the restore will work |
| If it conflicts or goes wrong, the stash is still there to retry. |
You want to apply the same stash to multiple branches |
| Pop would delete the stash after the first branch. |
Routine restore, you trust it's correct |
| Keeps the stash stack clean automatically. |
Stash is old and you're half-sure it's still useful |
| Inspect the result, decide whether to keep or |
You stashed accidentally and just want to undo it |
| Restores and tidies up in one go. |
What happens on success
A clean pop
git stash pop
# On branch feature/login
# Changes not staged for commit:
# modified: src/login.js
# Dropped refs/stash@{0} (a1b2c3d4e5f6...)What happens on conflict
When the branch moved on without you
git stash pop # Auto-merging src/login.js # CONFLICT (content): Merge conflict in src/login.js # The stash entry is kept in case you need it again.
popbecomes effectivelyapplywhen there's a conflict — the stash stays on the stack.Resolve the conflicts like any merge: edit,
git add, then manually drop the stash withgit stash droponce you're happy.applyalways leaves the stash, conflict or not.
Restoring the staged/unstaged split (--index)
Get back exactly the state you stashed
# Before stash: some files staged, some merely modified git stash push -m "split state" # A plain pop dumps everything into the working tree as unstaged git stash pop # (you have to git add the staged ones again) # With --index, Git tries to restore the staged/unstaged split git stash pop --index
--index is best-effort: if the staged content conflicts, Git falls back to a normal apply. But when it works, it preserves your exact pre-stash state — useful when you parked work mid-commit.
Applying a stash to a different branch
Stashes are portable
git switch feature/login git stash push -m "shared validation helper" # Realize this belongs on a different branch git switch feature/signup git stash apply # Conflicts may happen if the branches diverge in those files, # but the operation is totally legal.
Real-world recipe: apply same stash to multiple branches
Use apply, not pop
# Same lint config tweak needs to land on 3 release branches git stash push -m "shared eslint tweak" git switch release/1.x git stash apply # keep stash git commit -am "Update lint config" git switch release/2.x git stash apply git commit -am "Update lint config" git switch release/3.x git stash apply git commit -am "Update lint config" # Finally, clean up git stash drop
Real-world recipe: stash → switch → demo → pop
A two-minute interruption
git stash push -m "WIP: do not lose this" git switch main # show off main to a teammate # ...demo... git switch - # back to your feature branch git stash pop --index # restore exactly as it was
Common surprises
Pop on conflict does NOT drop. Always re-run
git stash listafter a conflicting pop. The stash is still there.--indexcan fail silently. Read the output; if Git couldn't restore the split, it tells you and falls back to a regular apply.Applying to an unrelated branch can dump huge diffs. Inspect with
git stash show -pfirst if you're not sure.git stash popwith the wrong stash index is hard to undo. When in doubt,applyfirst.