git stash apply: Usage, Options & Common CI Errors
By Daniel Zoghalchali·Latchkey
git stash apply reapplies a stash entry but leaves it on the stack for reuse.
Apply is the safe sibling of pop: because it does not drop the entry, you can retry if the apply goes wrong or reuse the same stash across multiple working trees.
What it does
git stash apply restores the changes from a stash entry onto the working tree without removing the entry, so the same stash can be applied again or dropped later by hand.
Common usage
Terminal
git stash apply
git stash apply stash@{1}
git stash apply --index # also reinstate the staged set
# apply, verify, then clean up:
git stash apply && make test && git stash drop
Options
Flag
What it does
[<stash>]
Apply a specific entry (default: latest)
--index
Try to restore the index state as well
-q / --quiet
Suppress informational output
Common errors in CI
error: Your local changes to the following files would be overwritten by merge - the working tree conflicts with the stash; commit or stash current work first. With --index, "Could not restore untracked files from stash" appears when the index state cannot be cleanly reproduced.
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 apply: Usage, Options & Common CI Errors?
Apply is the safe sibling of pop: because it does not drop the entry, you can retry if the apply goes wrong or reuse the same stash across multiple working trees.
What it does?
git stash apply restores the changes from a stash entry onto the working tree without removing the entry, so the same stash can be applied again or dropped later by hand.
Common errors in CI?
error: Your local changes to the following files would be overwritten by merge - the working tree conflicts with the stash; commit or stash current work first. With --index, "Could not restore untracked files from stash" appears when the index state cannot be cleanly reproduced.