📦 Half-finished Feature? Switch Branch Without Committing
Can’t switch branches with uncommitted changes. git stash saves changes, cleans working directory, restores later.
📝 Basic Stash
# Save changes
git stash
git stash push -m "WIP: login feature"
# List stashes
git stash list
# stash@{0}: On main: WIP: login feature
# stash@{1}: On feature: half-done work
# Apply latest stash (keeps in stash)
git stash apply
# Apply specific stash
git stash apply stash@{1}
# Pop (apply and remove)
git stash pop
# See what's in stash
git stash show -p stash@{0}
# Create branch from stash
git stash branch new-branch stash@{0}
# Clear all stashes
git stash clear
🎯 Advanced Stash
# Stash untracked files git stash -u # Stash everything (including ignored) git stash -a # Stash only specific files git stash push -m "partial" -- file1.txt file2.txt # Stash without staging git stash --keep-index # Interactive stash git stash save --patch
💡 Workflow
- Start feature, make changes
- Urgent bug fix needed → git stash
- Switch branch, fix bug, commit, push
- Switch back → git stash pop
- Continue feature work
“Emergency fix needed while deep in feature. Stashed changes, fixed bug, popped stash. No commit mess. Git stash is essential for context switching.”
