snippetbashgitTippending
Git stash advanced usage
Viewed 0 times
git stashnamed stashpartial stashstash popstash branch
Problem
Need to temporarily save work in progress, including untracked files, with the ability to find and restore it later.
Solution
Git stash beyond the basics:
Tip: Always use
# Basic stash
git stash # Stash tracked changes
git stash -u # Include untracked files
git stash -a # Include ignored files too
# Named stash (much easier to find later)
git stash push -m "WIP: login form validation"
# Stash specific files
git stash push -m "API changes" src/api/ src/types/
# Interactive stash (choose hunks)
git stash push -p # Patch mode - select what to stash
# List stashes
git stash list
# stash@{0}: On feature/auth: WIP: login form validation
# stash@{1}: On main: API changes
# View stash contents
git stash show stash@{0} # Summary
git stash show -p stash@{0} # Full diff
# Apply and keep in stash list
git stash apply stash@{0}
# Apply and remove from stash list
git stash pop stash@{0}
# Apply to a different branch
git checkout other-branch
git stash apply stash@{0}
# Create branch from stash
git stash branch new-branch stash@{0}
# Drop specific stash
git stash drop stash@{1}
# Clear all stashes
git stash clearTip: Always use
-m with descriptive messages. Without it, stashes are identified only by the auto-generated description.Why
Stash is essential for context switching, but unnamed stashes quickly become unidentifiable. Named stashes and partial stashing make it a powerful workflow tool.
Context
Git workflow when needing to temporarily set aside work
Revisions (0)
No revisions yet.