You’re halfway through a feature when a teammate pings you: “Hey, can you quickly fix this bug on another branch?”
You’ve got uncommitted changes. They’re messy. They’re incomplete. And committing them just to switch context feels wrong.
This is exactly where Git stash shines.
What Git Stash Actually Does
At its core, Git stash temporarily shelves your working directory changes so you can work on something else, then come back later and restore them.
Think of it like putting your work into a drawer instead of committing it to history.
Quick mental model
- Working directory = your current edits
- Stash = temporary storage
- Commit = permanent history
Stashing is not a replacement for commits. It’s a short-term escape hatch.
The Basic Workflow
Let’s start with the simplest use case.
1. Stash your changes
1git stashThis command:
- Saves your modified tracked files
- Reverts your working directory to a clean state
2. Switch branches
1git checkout main3. Come back and restore
1git stash popNow your changes are back, exactly where you left them.
Here’s Where Things Get Interesting
Most developers only use git stash and git stash pop. But stash has a lot more depth—and ignoring it leads to messy workflows.
Named stashes (you’ll thank yourself later)
Instead of creating anonymous stashes, give them context:
1git stash push -m "WIP: checkout form validation"This becomes incredibly useful when you have multiple stashes.
List your stashes
1git stash listExample output:
1stash@{0}: On feature/cart: WIP: fix pricing bug
2stash@{1}: On main: WIP: navbar redesignApply a specific stash
1git stash apply stash@{1}Unlike pop, this does not remove it from the stash list.
Pop vs Apply (Common Confusion)
This trips up a lot of people.
| Command | What it does |
|---|---|
| git stash pop | Applies changes and removes stash |
| git stash apply | Applies changes but keeps stash |
Use pop when you’re done with the stash. Use apply when you might need it again.
Stashing Untracked Files
By default, Git stash ignores untracked files.
If you want to include them:
1git stash -uOr even include ignored files:
1git stash -aThis is useful when you're working with generated files or temporary assets.
A Real-World Scenario
Let’s say you’re working on a React component:
- You’ve modified multiple files
- The code doesn’t compile yet
- A production bug needs urgent fixing
Instead of committing broken code:
1git stash push -m "WIP: product card redesign"
2
3git checkout hotfix/login-issueFix the bug, push it, then come back:
1git checkout feature/product-card
2
3git stash popYou resume exactly where you left off—no messy commit history.
Partial Stashing (Underrated Feature)
Sometimes you don’t want to stash everything.
You can stash interactively:
1git stash -pThis lets you choose which changes to stash, chunk by chunk.
Useful when:
- You’re working on multiple unrelated changes
- You only want to pause part of your work
Cleaning Up Your Stashes
Stashes can pile up quickly.
Drop a specific stash
1git stash drop stash@{0}Clear everything
1git stash clearBe careful—this is irreversible.
Common Mistakes Developers Make
1. Using stash as long-term storage
Stash is temporary. If something matters, commit it properly.
2. Forgetting about stashes
Old stashes can become irrelevant or incompatible with newer code.
3. Not naming stashes
“stash@{3}” tells you nothing. Always add context.
4. Assuming stash is branch-specific
Stashes are repository-wide. You can apply them on any branch.
When You Should (and Shouldn’t) Use Git Stash
Good use cases
- Quick context switching
- Interrupt-driven work
- Temporary experimentation
Not ideal for
- Long-running work
- Collaboration
- Anything you might forget
A Small Trick That Saves Time
You can stash and switch branches in one go:
1git stash && git checkout mainOr even:
1git stash push -m "quick save" && git switch mainNot groundbreaking, but handy in fast-paced workflows.
Wrapping It Up
Git stash is not just a convenience—it’s a workflow accelerator.
It keeps your commit history clean, lets you multitask safely, and removes the pressure to commit unfinished work.
Once you start naming stashes, using partial stash, and understanding apply vs pop, it becomes a much more powerful tool than most developers realize.
If you’ve ever made a “WIP commit” just to switch tasks, Git stash is the cleaner alternative.