How to Use git stash to Save Uncommitted Changes
git stash temporarily shelves uncommitted changes so you can switch branches cleanly, then restore them later with git stash pop.
Published September 20, 2026
git stash shelves your uncommitted changes so you get a clean working tree, and git stash pop brings them back. It is ideal when you must switch branches mid-task.
The concept
A stash is a commit-like snapshot of your tracked modifications stored on a stack, separate from any branch. The working tree is reset to match HEAD.
By default only tracked files are stashed; use -u to include untracked files and a message to find the stash later.
Shelve and restore
git stash push -m "half-done login"
Saved working directory and index state
git switch hotfix # ...fix and commit...
git switch feature && git stash pop
changes restored, stash dropped
Practical examples
Include untracked files
git stash push -u -m "with new files"List and apply a specific stash
git stash list
git stash apply stash@{1}Stash only some files
git stash push -m "only css" -- src/styles.cssClean up
git stash drop stash@{0}
git stash clearCommon mistakes
- Forgetting untracked files are not stashed without -u.
- Using pop and hitting a conflict, then losing track of the stash (it is kept on conflict).
- Piling up unnamed stashes you cannot identify.
Key takeaways
- stash push saves, pop restores, apply keeps a copy.
- Use -u and -m.
- Prefer a WIP commit for long-lived work.
FAQ
Pop vs apply?
pop applies and deletes the stash; apply applies and keeps it.
Can I turn a stash into a branch?
Yes: git stash branch new-branch stash@{0}.