Learn how to use Git Stash to save uncommitted changes, switch branches, and restore work efficiently. Essential commands & best practices explained.
Have you ever been in the middle of coding, needed to switch branches, but didn’t want to commit half-finished work? Git Stash is the solution!
This guide will explain:
✅ What Git Stash is and when to use it
✅ Essential Git Stash commands with examples
✅ Best practices and common pitfalls
What is Git Stash?
Git Stash temporarily saves your uncommitted changes (modified, staged, or untracked files) so you can switch branches, pull updates, or work on something else without losing progress.
When Should You Use Git Stash?
✔ Switching branches with uncommitted changes
✔ Saving work before pulling remote updates
✔ Temporarily storing experimental code
✔ Avoiding unnecessary “WIP” (Work in Progress) commits
Essential Git Stash Commands
1. Stash Your Changes
Save all modified and staged files (but not untracked files):
git stash
Save including untracked files:
git stash -u
Save with a custom message for easy identification:
git stash save "Feature X - WIP"
2. List All Stashes
View your stash history:
git stash list
Example output:
stash@{0}: On main: Feature X - WIP
stash@{1}: On dev: Bugfix Y - partial
3. Apply (Restore) a Stash
Restore the latest stash (keeps it in the stash list):
git stash apply
Restore a specific stash (e.g., stash@{1}):
git stash apply stash@{1}
4. Pop a Stash (Apply & Delete)
Restore the latest stash and remove it from the stash list:
git stash pop
- Delete a Stash Remove a specific stash:
git stash drop stash@{1}
Clear all stashes:
git stash clear
- Create a Branch from a Stash If your stash conflicts with current changes, create a new branch:
git stash branch new-branch-name stash@{1}
Conclusion
Git Stash is a powerful tool for managing unfinished work without cluttering your commit history. Whether you’re switching tasks, pulling updates, or experimenting, stash helps keep your workflow clean.
I’m Md Ariful Haque Sajib, a Software Engineer, specializing in PHP, Laravel, Spring Boot, Vue.js, and React.js. With expertise in E-commerce, Payment Gateways, APIs, various Management and Finance-based software. I am passionate about 🧠 learning and delivering 🌟 high-quality solutions.
📌 Follow me for updates and insights:
🌐 GitHub: ArifulHaque313
🔗 LinkedIn: Md Ariful Haque Sajib
📧 Contact: asajib7654@gmail.com
📢 Hashtags:
GitStash #Git #Github
ArifulHaqueSajib #arifulhaque313 #sajib
Hope this makes it more visually appealing! 😊
Top comments (0)