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 stackOptions
| 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.
Related guides
git checkout: Usage, Options & Common CI Errorsgit checkout switches branches and restores files. Reference for -b, --detach, and pathspecs, plus the detach…
git restore: Usage, Options & Common CI Errorsgit restore discards working-tree changes or unstages files. Reference for --staged, --source, --worktree, an…
git reset: Usage, Options & Common CI Errorsgit reset moves HEAD and optionally the index and working tree. Reference for --soft, --mixed, --hard, and ho…
git clean: Usage, Options & Common CI Errorsgit clean removes untracked files from the working tree. Reference for -n, -f, -d, -x, and the "would clobber…