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.
Aliases the pros type
Memorize the git stash concept, then let one of these shortcuts make it instant. Aliases are real git config keys — add one with:
git config --global alias.st # → git stash -u --include-untrackedg sgit stash -u --include-untrackedOh-my-zsh's default stash — safe, catches untracked files too.
g sagit stash applyRe-apply without popping (stack stays).
g slgit stash listSurvey the whole stack.
g spgit stash popRestore the newest stash and drop it.
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.
Pro tip
A stash is the only commit that belongs to no branch — dream state. If you never pop it, it's garbage-collected in 30 days by default (stash.stashExpire). Also: `git stash branch fix <stash>` makes conflicts vanish by placing the stash back where it belongs.