git stash is more powerful than most developers realise. Beyond the basic stash push / pop, you can stash only specific files, create stash branches, and use stashes as lightweight checkpoints when switching between hotfix and feature work on a WordPress project.
Problem: A stash contains a mix of related and unrelated changes, or needs to be applied to a different branch — the basic git stash pop workflow does not cover partial stashing or stash-to-branch conversion.
Solution: Use git stash push -p to interactively select hunks for a partial stash, git stash push -m "name" to create a named stash for easy reference, and git stash branch new-branch stash@{n} to convert a stash into a new branch when the stash would conflict with the current HEAD.
The examples below cover partial stashing with --patch, naming stashes, converting a stash to a branch, and the safest way to apply stash changes without losing them.
# Basic named stash
git stash push -m "wip: custom metabox refactor"
# Stash only specific files (leave everything else in the working tree)
git stash push -m "only functions.php" -- functions.php inc/helpers.php
# Interactively choose hunks to stash (like git add -p)
git stash push --patch
# Include untracked files (new files not yet git-added)
git stash push --include-untracked -m "with new block template"
# List stashes with timestamps
git stash list --date=relative
# stash@{0}: On feature/blocks: wip: custom metabox refactor
# stash@{1}: On main: only functions.php
# Inspect a stash without applying it
git stash show -p stash@{1}
# Apply a specific stash and keep it in the list
git stash apply stash@{1}
# Pop the most recent stash (apply + drop)
git stash pop
Convert a stash directly into a new branch — the safest way to continue stashed work:
# Creates a new branch from the commit where the stash was made,
# applies the stash, then drops it if there are no conflicts
git stash branch feature/metabox-refactor stash@{0}
# Clean up old stashes
git stash drop stash@{2} # drop one
git stash clear # drop ALL stashes — irreversible!
# Recover a dropped stash (within the GC window, ~30 days)
git fsck --unreachable | grep commit | awk '{print $3}' | xargs -I{} git log --oneline -1 {}
# Find the dangling commit hash, then:
git stash apply
NOTE: Use git stash branch whenever a stash would conflict with current HEAD changes — it avoids messy merge conflicts by replaying the stash on the original base commit.