You’re halfway through a feature, your working directory is messy, and suddenly—urgent bug fix. Classic.
This is where git stash quietly saves your day. But here’s the catch: most developers use it as a panic button rather than a deliberate strategy. Over time, that leads to forgotten changes, confusing stash lists, and occasional "where did my code go?" moments.
Let’s fix that by actually choosing a git stash strategy that works well with GitHub-based workflows.
What Git Stash Really Does (and Doesn’t)
At its core, git stash temporarily shelves your uncommitted changes so you can switch contexts safely.
Quick example:
1git stash
2git checkout main
3This saves your current modifications and resets your working directory.
But here’s where people trip up:
- Stashes are not tied to branches
- They’re easy to forget
- The default naming is not helpful
If you’re using GitHub for collaboration, this can create confusion quickly.
Start With Intent: When Should You Stash?
Not every interruption deserves a stash.
Use stash when:
- You need a quick context switch (e.g., urgent bug fix)
- Your changes are not ready to commit
- You want to experiment temporarily
Don’t use stash when:
- The work is meaningful and should be versioned → commit instead
- You’ll need the changes later but might forget → create a branch
A common mistake developers make is treating stash like long-term storage. It’s not.
Give Your Stash a Name (Seriously)
By default, Git labels stashes like this:
1stash@{0}: WIP on feature-xThat’s not helpful after a few hours.
Instead, use:
1git stash push -m "partial login validation refactor"Now your stash list becomes readable:
1git stash list1stash@{0}: partial login validation refactor
2stash@{1}: fix header alignment
3This small habit dramatically improves your workflow, especially in larger GitHub projects.
Partial Stashing: The Underrated Trick
Here’s where things get interesting.
You don’t have to stash everything.
Use interactive mode:
1git stash -pThis lets you choose specific changes to stash.
Why this matters:
- Keep relevant work in your current branch
- Stash only the noisy or unrelated changes
This is especially useful when preparing clean commits for GitHub pull requests.
Working Across Branches Without Chaos
Because stashes are global, not branch-specific, things can get messy.
Better approach:
- Stash your changes
- Create a new branch
- Apply the stash there
1git stash
2git checkout -b hotfix/login-bug
3git stash applyThis avoids polluting your original branch and keeps your GitHub history clean.
Apply vs Pop: Choose Carefully
Two commands, subtle difference:
git stash apply→ keeps the stashgit stash pop→ applies and deletes it
If you're unsure, always start with apply.
Why?
If something breaks or conflicts occur, you still have a backup.
Handling Conflicts After Stashing
Yes, stash can cause merge conflicts.
Especially when:
- The base branch has changed significantly
- You switch branches before applying
When this happens:
- Resolve conflicts like a normal merge
- Stage changes
- Continue working
There’s no magic here—stash isn’t conflict-proof.
Cleaning Up: Don’t Let Stashes Rot
Run this occasionally:
1git stash listIf you see entries from last week… that’s a smell.
Remove unused stashes:
1git stash drop stash@{2}Or wipe everything:
1git stash clearIn a GitHub-driven workflow, lingering stashes often mean unfinished or forgotten work.
GitHub Workflow Integration
Git stash doesn’t exist on GitHub—it’s purely local. But it still affects your GitHub workflow indirectly.
Here’s how it fits in:
- Use stash before switching to another issue branch
- Keep pull requests focused by stashing unrelated changes
- Avoid committing experimental or broken code
But remember:
If something matters to your team, it belongs in a commit—not a stash.
A Practical Workflow Example
Let’s say you’re working on a feature:
1git checkout feature/payment-flowYou get interrupted by a production issue.
Instead of committing incomplete work:
1git stash push -m "WIP payment validation edge cases"1git checkout main
2git checkout -b hotfix/payment-crashFix the issue, push to GitHub, open PR.
Then return:
1git checkout feature/payment-flow
2git stash applyClean, controlled, and no messy commits.
Where Git Stash Falls Short
It’s not perfect.
- No visibility on GitHub
- Easy to forget
- Not collaborative
For longer-term work, consider:
- Draft commits
- Feature branches
- GitHub draft pull requests
Stash is best for short-lived, local context switches.
Choosing Your Stash Strategy
If you take one thing from this: be intentional.
A solid git stash strategy looks like this:
- Name your stashes
- Keep them short-lived
- Use partial stashing when needed
- Prefer branches for anything meaningful
- Clean up regularly
Once you treat stash as a tool—not a dumping ground—your GitHub workflow becomes noticeably smoother.
And fewer “wait, where did that code go?” moments is always a win.