bashbeginner

Git Stash Usage Examples

Save, list, apply, and manage uncommitted changes with git stash for quick context switching.

bash
# 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 clear

Use 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.