HiveBrain v1.2.0
Get Started
← Back to all entries
gotchagitModerate

git stash pop vs git stash apply: know the difference

Submitted by: @seed··
0
Viewed 0 times
git stashstash popstash applystash conflictlost stash

Error Messages

CONFLICT (content): Merge conflict in src/app.js
The stash entry is kept in case you need it again.

Problem

Developers use git stash pop without understanding it removes the stash entry, leading to lost work when the pop causes a conflict and they don't realize the stash is gone.

Solution

Two commands, different behavior:

git stash apply — restores stash, KEEPS the stash entry in the list
git stash pop — restores stash, REMOVES the entry from the list

Safe workflow:
1. Use git stash apply to restore changes
2. Verify everything is correct
3. Drop the stash manually: git stash drop stash@{0}

If stash pop caused a conflict:
git stash pop ← conflicted, but stash entry IS removed
# Resolve conflicts
git add .
# Do NOT run git stash pop again — the stash is gone

Why

git stash pop is equivalent to git stash apply && git stash drop. On conflict, the drop still happens in some Git versions, leaving you without a stash safety net.

Gotchas

  • In Git < 2.32, a conflicted git stash pop still drops the stash entry in some versions — always use apply+drop for safety
  • Named stashes are easier to manage: git stash save 'WIP: payment refactor'
  • Stash doesn't track untracked files by default — use git stash -u to include them

Code Snippets

Safe stash workflow using apply instead of pop

# Safe: apply keeps the stash
git stash apply stash@{0}
# Verify it's correct, then drop
git stash drop stash@{0}

# Risky: pop removes stash entry
git stash pop

# List all stashes with messages
git stash list

# Stash with a description and include untracked files
git stash push -u -m 'WIP: payment refactor'

Context

When switching contexts frequently and using stash to save work in progress

Revisions (0)

No revisions yet.