# git stash apply: Usage, Options & Common CI Errors

> git stash apply reapplies a stash but keeps it on the stack. Reference for stash@{n}, --index, and when to choose apply over pop in repeatable CI steps.

Source: https://latchkey.dev/learn/command-reference/git-stash-apply  
Updated: 2026-06-25

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@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
```

> `git rev-parse --abbrev-ref HEAD` returns the literal string `HEAD` on a detached checkout rather than a branch name. On GitHub Actions read `github.ref_name` instead; the git command cannot know what it was checked out for.

## FAQ

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

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
