Skip to content
LatchkeyLatchkey home

git stash: Usage, Options & Common CI Errors

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

FlagWhat it does
push -u / --include-untrackedAlso stash untracked files
push -a / --allAlso stash ignored files
popReapply and drop the latest stash
applyReapply but keep the stash
drop / clearRemove 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

Frequently asked questions

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.

Related guides

References

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