git stash saves uncommitted changes and cleans your working directory, so you can switch branches quickly (for example, to fix an urgent bug).
git stash / git stash push -m "message"
git stash list
git stash pop: re-apply the latest stash and remove it.
git stash apply: re-apply but keep it in the list.
💡 Key Takeaways: Git Stash
Mastering Git Stash helps you write clean and reliable Git code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
Git Stash Code Example
Git
git stash push -m "half-done navbar"
git switch main
# ...fix the urgent bug, commit...
git switch feature-navbar
git stash pop
Output
Saved working directory and index state On feature-navbar: half-done navbar
Switched to branch 'main'
Switched to branch 'feature-navbar'
Dropped refs/stash@{0}
Run this example on your own computer. The "Get Started" lesson shows how to set it up.
Git Stash Practice Exercises
Check what you learned in “Git Stash”.
/ 2 solved
Fill in the blank
Re-apply the latest stash and remove it from the list.