git stash pop reapplies your most recent stash and drops it from the stack on success.
Pop is apply-then-drop in one step. The subtlety automation must handle: on a conflict, pop reapplies the changes but keeps the stash entry, so the stack is not actually cleaned up.
What it does
git stash pop applies the changes from a stash entry (the latest by default) back onto the working tree, then deletes that entry - but only if the apply succeeds without conflicts.
Common usage
Terminal
git stash pop
git stash pop stash@{2}
git stash pop --index # also restore the staged/unstaged split
git stash list # confirm the stack
Options
Flag
What it does
[<stash>]
Pop a specific entry (default: stash@{0})
--index
Restore index state too, not just the worktree
-q / --quiet
Suppress output
Common errors in CI
On conflict, pop prints "The stash entry is kept in case you need it again" and exits non-zero - the entry stays on the stack. Resolve, git add, then git stash drop manually. "No stash entries found" also exits non-zero; guard pop in scripts that may run with an empty stack.
Using this in CI
CI checkouts are shallow and detached by default, which changes the answer this command gives you. Commands that read history, branch names, or tags need the checkout configured for it.
.github/workflows/ci.yml
- uses:actions/checkout@v4with:fetch-depth:0 # history, tags, and git describe all need this- run:|git rev-parse --is-shallow-repository # expect falsegit rev-parse --abbrev-ref HEAD # prints HEAD when detached
Frequently asked questions
git stash pop: Usage, Options & Common CI Errors?
Pop is apply-then-drop in one step. The subtlety automation must handle: on a conflict, pop reapplies the changes but keeps the stash entry, so the stack is not actually cleaned up.
What it does?
git stash pop applies the changes from a stash entry (the latest by default) back onto the working tree, then deletes that entry - but only if the apply succeeds without conflicts.
Common errors in CI?
On conflict, pop prints "The stash entry is kept in case you need it again" and exits non-zero - the entry stays on the stack. Resolve, git add, then git stash drop manually. "No stash entries found" also exits non-zero; guard pop in scripts that may run with an empty stack.