bashbeginner

Git Stash — Named, Partial, and Pop Strategies

Advanced stash techniques: named stashes, partial stash, stash apply vs pop, and branch from stash.

bash
# Stash with a descriptive message
git stash push -m "WIP: refactoring auth module"

# Stash only specific files
git stash push -m "partial: only api changes" -- src/api/ src/routes/

# Stash including untracked files
git stash push --include-untracked -m "with new files"

# Stash only staged changes (keep unstaged)
git stash push --staged -m "staged only"

# Interactive stash (choose hunks)
git stash push -p -m "selected hunks"

# List all stashes
git stash list
# stash@{0}: On main: WIP: refactoring auth module
# stash@{1}: On feature: partial: only api changes

# Apply without removing from stash list
git stash apply stash@{0}

# Apply AND remove from stash list
git stash pop stash@{0}

# Create a branch from a stash
git stash branch new-feature stash@{1}

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

# Drop a specific stash
git stash drop stash@{1}

# Clear all stashes (careful!)
git stash clear

Use Cases

  • Saving work in progress before switching branches
  • Stashing only selected changes for review
  • Creating branches from old stashed work

Tags

Related Snippets

Similar patterns you can reuse in the same workflow.