Vasu Patel logoVasu Patel
← Git Mastery
All chapters in this track
  1. 011. The Mental Model
  2. 022. Essential Setup
  3. 033. Core Daily Workflow
  4. 044. Branching
  5. 055. Merging & Conflict Resolution
  6. 066. Rebasing
  7. 077. Remote Repositories
  8. 088. Stashing
  9. 099. Undoing Things
  10. 1010. Tagging & Versioning
  11. 1111. Cherry-Pick
  12. 1212. Git Bisect & Blame
  13. 1313. Git Hooks
  14. 1414. Submodules
  15. 1515. Team Workflows
  16. 1616. Power Commands & Aliases
  17. 1717. Reflog: The Safety Net
  18. 1818. Practice Tasks
  19. 19Quick Reference Cheatsheet

Chapter 8 of 19

8. Stashing

Stash lets you temporarily shelve changes without committing.

# Save stash
git stash                        # stash tracked changes
git stash push -m "login WIP"   # named stash
git stash -u                     # include untracked files
git stash -a                     # include ignored files too

# List stashes
git stash list
# stash@{0}: On main: login WIP
# stash@{1}: WIP on feature/x: a3b2c1 ...

# Apply
git stash pop                    # apply top stash + remove it
git stash apply stash@{1}        # apply specific stash, keep it
git stash drop stash@{0}         # delete a stash
git stash clear                  # delete ALL stashes

# Inspect
git stash show -p stash@{0}      # diff of a stash

# Create branch from stash
git stash branch feature/rescued stash@{0}

When to stash:

  • You need to switch branches but aren't ready to commit
  • A teammate asks you to review their branch immediately
  • You want to test clean state (stash your changes, run tests)