Git Stash Usage Examples
Save, list, apply, and manage uncommitted changes with git stash for quick context switching.
# Stash current changes (tracked files)
git stash
# Stash with a descriptive message
git stash push -m "WIP: authentication flow"
# Stash including untracked files
git stash push -u -m "WIP: includes new files"
# Stash only specific files
git stash push -m "partial stash" src/auth.ts src/utils.ts
# List all stashes
git stash list
# Apply most recent stash (keep in stash list)
git stash apply
# Apply and remove from stash list
git stash pop
# Apply a specific stash
git stash apply stash@{2}
# View stash contents
git stash show -p stash@{0}
# Create a branch from a stash
git stash branch new-branch stash@{0}
# Drop a specific stash
git stash drop stash@{1}
# Clear all stashes
git stash clearUse Cases
- Switching branches with uncommitted work
- Temporarily shelving changes for code review
- Saving partial work before pulling updates
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
Git Rebase Workflow Example
Step-by-step git rebase workflow to keep feature branches up to date with main branch cleanly.
Undo Last Git Commit (Soft and Hard)
Git commands to undo the last commit while keeping changes staged, unstaged, or fully discarded.
Git Cherry-Pick Commits Example
Apply specific commits from one branch to another using cherry-pick with conflict resolution.
Squash Multiple Git Commits
Interactive rebase to squash multiple commits into one clean commit before merging a feature branch.