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

> git stash pop reapplies the latest stash and removes it from the stack. Reference for stash@{n}, --index, and the conflict-keeps-the-entry behavior in CI.

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

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

---

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
