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@v4with:fetch-depth:0 # history, tags, and git describe all need this- run:|git rev-parse --is-shallow-repository # expect falsegit 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.