Stashing Work in Progress
An urgent bug always strikes mid-feature. git stash lets you shelve your half-finished work, deal with the interruption on a clean tree, then restore everything exactly as it was. By the end you'll stash, list, pop, apply, and drop with confidence.
Learn Stashing Work in Progress in our free Git course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a quick reference.
Part of the free Git course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
What You'll Learn
1️⃣ git stash — Shelve and Restore
git stash takes your uncommitted (tracked) changes off the working tree and stores them safely, leaving a clean tree behind. You can then switch branches freely. When you return, git stash pop puts everything back exactly as it was and removes the stash. It's the perfect interruption handler.
2️⃣ Managing the Stash Stack
Stashes form a last-in, first-out stack : the newest is always stash@ { 0 } . git stash list shows them all. apply restores a stash but keeps it on the stack; pop restores and removes it. drop deletes one without restoring, and clear wipes them all.
3️⃣ Stashing Untracked Files (-u)
Here's the gotcha that catches everyone: plain git stash does not stash untracked files — brand-new files Git isn't following yet. They stay behind in your working tree. Add -u (or --include-untracked ) to shelve those too, so the tree is truly clean.
Your turn. Shelve a change, check the shelf, and bring it back. Fill in the three blanks.
Common Errors (and the fix)
- "No local changes to save": there was nothing tracked to stash. If you only have new files, use git stash -u to include untracked ones.
- New file vanished from the stash: plain stash skips untracked files. Always use -u when new files are involved.
- pop caused a conflict: the branch changed under you. Resolve the conflict like a merge; the stash is not dropped on a conflicting pop, so your work is safe.
- Lost a stash with drop/clear: those remove stashes without restoring. Double-check git stash list before clearing.
Pro Tips
- 💡 Name your stashes: git stash push -m "wip: search box" makes list readable.
- 💡 Use apply when reusing: apply the same stash to multiple branches, then drop it when done.
- 💡 Don't hoard stashes: review git stash list often — forgotten stashes pile up.
- 💡 Branch from a stash: git stash branch new-branch restores a stash onto a fresh branch.
📋 Quick Reference
Command
Purpose
git stash
Shelve tracked changes, clean the tree
git stash -u
Stash untracked files too
git stash list
Show all stashes (stack)
git stash pop
Restore latest stash and remove it
git stash apply
Restore latest stash and keep it
git stash drop
Delete a stash without restoring
git stash clear
Delete all stashes
Frequently Asked Questions
Mini-Challenge: Juggle Two Stashes
No commands given this time — just the plan. Stack two stashes, target them by name, and clean up.
🎉 Lesson Complete!
- ✅ git stash shelves tracked changes and cleans the tree
- ✅ Stashes are a LIFO stack — newest is stash@ { 0 }
- ✅ pop restores and removes; apply restores and keeps
- ✅ drop deletes one stash; clear deletes them all
- ✅ Plain stash skips untracked files — use -u to include them
- ✅ Next lesson: keep junk out of your repo with .gitignore
Practice quiz
What does do?
- Deletes your uncommitted changes
- Commits your changes
- Shelves your uncommitted changes and cleans the working directory
- Pushes to the remote
Answer: Shelves your uncommitted changes and cleans the working directory. git stash saves your uncommitted work onto a stack and resets the working tree to a clean state.
By default, does plain include UNTRACKED files?
- No — only tracked changes are stashed by default
- Yes, always
- Only files over 1MB
- Only files in subfolders
Answer: No — only tracked changes are stashed by default. Plain git stash leaves untracked files alone; use -u to include them.
Which flag stashes untracked files along with tracked changes?
- git stash -a
- git stash -t
- git stash --all-tracked
- git stash -u
Answer: git stash -u. git stash -u (or --include-untracked) also shelves untracked files.
What does do?
- Lists all stashes
- Restores the latest stash AND removes it from the stack
- Deletes the latest stash without restoring
- Renames a stash
Answer: Restores the latest stash AND removes it from the stack. pop applies the most recent stash and then drops it from the list.
How does differ from ?
- apply restores but KEEPS the stash in the list
- apply deletes the stash
- apply only works once
- There is no difference
Answer: apply restores but KEEPS the stash in the list. apply restores the changes but leaves the stash on the stack, so you can reuse it.
Which command shows all your saved stashes?
- git stash show-all
- git stash log
- git stash list
- git stash -l
Answer: git stash list. git stash list prints the stack, each entry labelled like stash@{0}.
How are stashes ordered on the stack?
- Oldest first
- Last-in, first-out — the newest is stash@{0}
- Alphabetically
- Randomly
Answer: Last-in, first-out — the newest is stash@{0}. Stashes form a LIFO stack; stash@{0} is the most recent one you saved.
What does do?
- Restores a stash
- Lists stashes
- Creates a branch from a stash
- Deletes a stash WITHOUT restoring it
Answer: Deletes a stash WITHOUT restoring it. drop removes a stash entry from the stack without applying it.
A common reason to stash is...
- To compress the repo
- To switch branches quickly without committing half-finished work
- To delete a branch
- To rename commits
Answer: To switch branches quickly without committing half-finished work. Stashing gives you a clean working tree so you can switch branches and come back later.
After succeeds, what does typically show?
- A merge conflict
- All your changes still there
- A clean working tree (nothing to commit)
- An error
Answer: A clean working tree (nothing to commit). Stashing removes the changes from the working tree, leaving it clean.