GitApply vs Pop

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}

Bash
git stash apply        # apply stash@{0}, leave it on the stack
git stash pop          # apply stash@{0}, then drop it if clean
Targeting a specific stash

Any index works

Bash
git stash apply stash@{2}
git stash pop   stash@{2}

# Bare numbers also work in modern Git
git stash pop 2
Apply vs pop — when to choose which

Situation

Use

Why

You're unsure the restore will work

apply

If it conflicts or goes wrong, the stash is still there to retry.

You want to apply the same stash to multiple branches

apply

Pop would delete the stash after the first branch.

Routine restore, you trust it's correct

pop

Keeps the stash stack clean automatically.

Stash is old and you're half-sure it's still useful

apply

Inspect the result, decide whether to keep or drop.

You stashed accidentally and just want to undo it

pop

Restores and tidies up in one go.

What happens on success

A clean pop

Bash
git stash pop
# On branch feature/login
# Changes not staged for commit:
#   modified:   src/login.js
# Dropped refs/stash@{0} (a1b2c3d4e5f6...)
The last line is the proof that the stash was removed. If you do not see "Dropped refs/stash@{0}", the stash is still there.
What happens on conflict

When the branch moved on without you

Bash
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.
  • pop becomes effectively apply when there's a conflict — the stash stays on the stack.

  • Resolve the conflicts like any merge: edit, git add, then manually drop the stash with git stash drop once you're happy.

  • apply always leaves the stash, conflict or not.

Why pop doesn't drop on conflict
This is intentional safety. If the merge is messy, you may decide to abort and reapply elsewhere. Pop keeping the stash means you don't lose anything during conflict resolution.
Restoring the staged/unstaged split (--index)

Get back exactly the state you stashed

Bash
# 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

Bash
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.
Tip
This is one of stash's superpowers. You can experiment on branch A, realize the change makes more sense on branch B, switch, and apply. If the diff is small, it almost always applies cleanly.
Real-world recipe: apply same stash to multiple branches

Use apply, not pop

Bash
# 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

Bash
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 list after a conflicting pop. The stash is still there.

  • --index can 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 -p first if you're not sure.

  • git stash pop with the wrong stash index is hard to undo. When in doubt, apply first.

Mental model: apply is read, pop is read-and-remove
Think of `apply` like browsing a clipboard and `pop` like cutting from it. When you're unsure, browse first.