- Readers pausing work without making a real commit yet
Command Reference
git stash Tutorial
Explains how to temporarily shelve local changes with git stash and later inspect, restore, or remove stash entries.
- Understanding that stash is not an all-purpose backup
- Knowing the difference between apply and pop
- Assuming stash preserved everything automatically
- Letting the stash stack become untracked long-term context
The short version
git stash temporarily shelves your uncommitted work so you can switch tasks and come back later.
The most useful framing is to treat stash as a short-term holding area, not as a long-term archive or branch replacement.
Good use cases
- you need to jump to another branch quickly
- the work is not ready to commit yet
- you want to preserve a short-lived experiment without keeping it in the working tree
Common operations
Save current work
git stash push -m "wip: login form"
Inspect stash entries
git stash list
Reapply the latest stash
git stash apply
Reapply and remove it
git stash pop
Inspect what a stash contains
git stash show -p stash@{0}
Two advanced but very practical patterns
Include untracked files
git stash push -u -m "wip: include new files"
Stash only part of the tree
git stash push src/checkout.ts
apply vs pop
apply: restore but keep the stash entrypop: restore and delete it if successful
If you are not fully sure yet, apply is usually the safer option.
That is why the diagram highlights apply / pop as a separate step. Many stash mistakes happen there: pop is convenient, but it bundles “restore the changes” with “try to remove the stash entry,” while apply keeps the recovery path more conservative.
A safer restore workflow
Instead of immediately using pop, a safer sequence is often:
git stash listgit stash show -p stash@{0}git stash apply stash@{0}- confirm the result
git stash drop stash@{0}
Two practical habits
Always add a message
git stash push -m "wip: checkout flow"
That makes git stash list much easier to read later.
Prefer apply before deleting
For important work, restoring first and deleting later is often safer than using pop immediately.
Why stash restores can still conflict
Stash records a set of changes, but the surrounding code may have changed by the time you reapply it. That is why apply and pop can still produce conflicts.
A practical decision rule
- use stash for short interruptions
- use branches for work that lives longer than a quick context switch
- use commits and branches for anything reviewable or shared
What problem this command solves in a workflow
git stash solves the problem of "I need to temporarily set aside my uncommitted work so I can switch branches and come back later." It saves both the working tree and index state onto a stack, letting you park unfinished changes without committing them.
Typical use cases
- When you need to jump to another branch quickly but your current work is not ready to commit, use
git stash pushto save the state and get a clean working tree. - Inspect saved stashes with
git stash listand review their content withgit stash show -p stash@{0}before reapplying. - Use
git stash push -uto also include untracked files in the stash entry, so nothing is left behind when you switch context.
Diagram view
Special cases and boundaries
- Stash records a set of changes, but the surrounding code may have changed by the time you reapply it — apply and pop can still produce conflicts.
- Use
applyto restore changes while keeping the stash entry as a safety net, orpopto restore and remove the entry in one step. - Untracked files only travel with the stash entry when you use
-u(or-afor ignored files too). - For important work that will continue for hours or days, a branch is usually a better fit than a growing stash pile.
Try it yourself
The fragile moment in stash is usually restore time, not save time. This drill turns the safer habit into a repeatable routine.
git switch -c lab/stash-demo # edit one tracked file and create one untracked fileTry it
- Run `git stash push -u -m "wip: stash demo"`.
- Inspect the entry with `git stash show -p stash@{0}`.
- Restore with `git stash apply stash@{0}` first, and only then decide whether to run `git stash drop stash@{0}`.
- You will see that untracked files only travel with stash when you use `-u`.
- `apply` restores the work while keeping the stash entry as a safety net.
- Dropping after inspection is more conservative than going straight to `pop`.
- If the work will continue for hours or days, a branch is usually a better fit than a growing stash pile.
- Do not jump to `pop` before checking what the stash actually contains.
- A conflict during apply usually means the surrounding code changed, not that the stash is broken.