The Git Stash
Temporarily save messy, uncommitted work so you can safely switch context.
The Temporary Shelf
git stash takes the dirty state of your working directory (modified tracked files and staged changes) and saves it onto a stack of unfinished changes.
It then cleans your working directory so it exactly matches the HEAD commit, giving you a clean slate.
Why it matters
Web developers constantly juggle tasks. You might be halfway through building a complex React component when an urgent bug report requires you to switch branches immediately.
You cannot commit broken code, and you cannot switch branches with conflicting uncommitted changes. The stash allows you to save this messy work temporarily, fix the bug, and seamlessly restore your progress later.
How it works
**Pushing to the Stack:** Running git stash packages your current changes into a temporary commit and pushes it onto a local stack (a Last-In, First-Out queue).
**Popping/Applying:** When you return, git stash pop applies the most recent stashed changes to your working directory and removes them from the stack. git stash apply does the same but leaves a copy on the stack.
Check yourself
Pick an answer to lock it in, then read why. Getting one wrong is part of how it sticks.
Remember this
- Stash saves uncommitted work and cleans your working directory.
- It allows you to safely switch branches mid-task.
- Use
stash popto apply and delete, orstash applyto just apply. - Always name your stashes using
stash push -m.
Done with this concept?
Mark it complete to track your progress. No login needed.