Skip to content
LatchkeyLatchkey home

git stash apply: Usage, Options & Common CI Errors

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

FlagWhat it does
[<stash>]Apply a specific entry (default: latest)
--indexTry to restore the index state as well
-q / --quietSuppress 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@v4
  with:
    fetch-depth: 0   # history, tags, and git describe all need this

- run: |
    git rev-parse --is-shallow-repository   # expect false
    git 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.

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card