📦 Git Stash = Developer Superpower
Context switching is a developer’s nightmare. Git stash lets you save work and switch contexts instantly.
📝 Stash Techniques
# Save Work
git stash save "WIP: Feature X - auth implementation"
# Save with Untracked Files
git stash save -u "WIP: Feature X - new files"
# Save with Index (Staged Changes)
git stash save --keep-index "WIP: half-staged work"
# Multiple Stashes
git stash save "Feature A - UI"
git stash save "Feature B - API"
git stash save "Feature C - Tests"
# List Stashes
git stash list
# stash@{0}: On feature-c: Tests
# stash@{1}: On feature-b: API
# stash@{2}: On feature-a: UI
# Apply Specific Stash
git stash apply stash@{1}
# Apply and Remove
git stash pop stash@{1}
# Create Branch from Stash
git stash branch new-feature stash@{0}
🎯 Advanced Stash Operations
# Stash Diff
git stash show stash@{0} # Summary
git stash show -p stash@{0} # Full diff
# Partial Apply (files only)
git checkout stash@{0} -- path/to/file
# Stash Cleanup (remove old stashes)
# Remove stashes older than 30 days
git stash list --format='%ci %gd' | \
awk '{ cmd="git stash drop " $NF; if (system("date -d \"" $1 " " $2 "\" +%s") < system("date -d \"30 days ago\" +%s")) system(cmd)'
# Stash with Rebase
git stash save "WIP before rebase"
git rebase main
git stash pop
# Team Collaboration
# Developer A stashes work
git stash save "WIP: Feature X"
# Share stash hash
git stash apply 123abc
# CI/CD Integration
git stash save "test-state"
# ... run tests ...
git stash pop # Restore changes
💡 Stash Best Practices
- Use descriptive messages
- Clean up old stashes regularly
- Use `pop` for immediate application
- Use `apply` for safe testing
- Resolve conflicts before returning
Git stash is the unsung hero of productive development. It enables seamless context switching without losing work.
