git stash
intermediatePark your uncommitted changes and get a clean working tree.
git stashWhat it does
git stash sweeps your staged and unstaged changes out of the working tree and stores them as specially-marked commit objects on the stash stack. Your worktree becomes clean instantly. You can pop the stash back anytime — even days later, even on another branch.
Working Tree
before git stash
Stash Stack
refs/stash · LIFO
Changes are packed into a stash object and emptied from the worktree
Watch it — press play
A narrated, step-by-step walkthrough that shows how to do it — not just theory. It adapts to the learner mode you picked in the top bar.
Step 1
Interrupted mid-feature
Half-finished changes sit in your worktree, but you must switch branches now.
git stashWorking Tree
files on disk
Index · Staging
.git/index
Repository
objects/ → commits
committed history
Uncommitted work you don't want to lose
Under the hood
A stash is a pair of commits
Git commits your index as one commit and your working-tree changes as a second, both hanging off your current HEAD under a special stash ref. That ref moves like a stack: push (stash) / pop (stash pop).
W-index = stash of staged
W's-worktree = stash of unstaged
stash@{0} → parent → your HEADThe working tree is then forced clean
After recording, git stash resets the worktree to HEAD — quietly running the same file-discard logic as restore. Files that only existed locally become untracked unless -u was given.
The stack is ordered, not merged
stash@{0} is the newest. git stash pop applies and drops, git stash apply applies and keeps, git stash list shows all. Stashes are unmerged unless you explicitly apply.
Command anatomy
-uAlso stash untracked files (otherwise they stay around).
push -m <msg>Name the stash so you remember what it was.
popApply the newest stash and remove it from the stack.
list / showInspect the stack without touching anything.
branch <name>Create a branch at the stash's base and apply — conflict-annihilation.
When to reach for it
A client calls mid-feature; you need to switch branches NOW: stash, switch, work, switch back, pop.
You want to test one set of changes in isolation.
Your stash stack becomes a lightweight scratchpad of work-in-progress.
Practice
A real repo, pre-seeded with history, runs right here — stage, commit, branch, stash, diff, even hit and resolve a real merge conflict. Nothing to install, nothing leaves your machine.
Open practice playground