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.
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.
📋 Quick Reference
No commands given this time — just the plan. Stack two stashes, target them by name, and clean up.
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.