# git stash: Usage, Options & Common CI Errors

> git stash saves uncommitted changes aside and restores a clean tree. Reference for push, pop, -u, list, and the conflict-on-pop errors in CI.

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

git stash tucks away your uncommitted changes so you get a clean working tree, then brings them back later.

Stash is handy for parking work mid-task. In automation, watch for conflicts when popping.

## What it does

git stash records the current state of the working tree and index on a stack and reverts to a clean HEAD. git stash pop reapplies the most recent entry and removes it from the stack.

## Common usage

```Terminal
git stash                     # stash tracked changes
git stash push -u             # include untracked files
git stash push -m "wip" path/ # stash a subset with a label
git stash list
git stash pop                 # reapply + drop
git stash apply               # reapply, keep on stack
```

## Options

| Flag | What it does |
| --- | --- |
| push -u / --include-untracked | Also stash untracked files |
| push -a / --all | Also stash ignored files |
| pop | Reapply and drop the latest stash |
| apply | Reapply but keep the stash |
| drop / clear | Remove one / all stash entries |

## Common errors in CI

On conflict, pop leaves the entry on the stack and prints conflict markers; "The stash entry is kept in case you need it again." Resolve, git add, then git stash drop. "No local changes to save" exits non-zero - guard stash calls in scripts.

## 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: Usage, Options & Common CI Errors?

Stash is handy for parking work mid-task. In automation, watch for conflicts when popping.

### What it does?

git stash records the current state of the working tree and index on a stack and reverts to a clean HEAD. git stash pop reapplies the most recent entry and removes it from the stack.

### Common errors in CI?

On conflict, pop leaves the entry on the stack and prints conflict markers; "The stash entry is kept in case you need it again." Resolve, git add, then git stash drop. "No local changes to save" exits non-zero - guard stash calls in scripts.

---

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
