Git Stash

Put work aside temporarily.

✍️ 2 exercises in this lesson

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.

git stash 
✓ Correct! Not quite. Try again.
Multiple choice

When is git stash useful?

✓ Correct! Not quite. Try again.
to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services