Master Git Stash with Named Entries, Untracked Files, and Patch Mode

Git stash saves uncommitted changes onto a stack and restores a clean working tree, making it the fastest way to switch context without committing work-in-progress or losing local modifications. Unlike a branch switch, stashing does not require a commit message and does not create a new entry in the repository history — the stash stack is local to your clone and is not pushed to remote repositories. The default git stash push saves tracked modifications and staged changes but ignores untracked files unless you add the --include-untracked flag — forgetting this flag leaves new files behind when switching branches. Naming stash entries with git stash push -m "description" makes a crowded stash list readable, especially when juggling multiple work streams across a week. git stash list displays all entries with their stack index and description; git stash show -p stash@{2} shows the full diff of a specific entry before applying it, preventing surprises on a restored working tree. git stash pop applies the most recent stash and removes it from the stack, while git stash apply applies without removing, useful when testing whether a stash applies cleanly before committing to the pop. git stash branch feature/xyz creates a new branch, checks it out, and applies the stash — the cleanest recovery path when a stash has grown too large to merge back into the original branch cleanly. The --patch flag for git stash push opens an interactive hunk selector identical to git add -p, letting you stash only part of a changed file while leaving the rest in the working tree. The Git aliases post shows how to create short aliases for the stash commands used daily, reducing git stash push --include-untracked -m to a few keystrokes. The Git worktrees guide is the long-term alternative to stashing — when context switching between branches happens several times a day, parallel worktrees eliminate stashing entirely. Clear stash entries older than a sprint regularly with git stash drop stash@{N} — stale stash entries that conflict with current branch history become progressively harder to apply and create confusion about what work is actually pending.

Problem: Switching WordPress feature branches mid-task without committing work-in-progress risks losing local changes or carrying them into the wrong branch, and the default git stash command silently omits new untracked files.

Solution: Use git stash push --include-untracked -m "description" to safely stash all changes including new files, and use git stash show -p to preview a stash entry before applying it back to the working tree.

# Save current work including new untracked files
git stash push --include-untracked -m "wip: checkout redesign form styles"

# List all stash entries with indices
git stash list
# stash@{0}: On feature/checkout: wip: checkout redesign form styles
# stash@{1}: On main: wip: header menu hover fix

# Preview a specific stash as a diff before applying
git stash show -p stash@{1}

# Apply the most recent stash and remove it from the stack
git stash pop

# Apply a specific stash without removing it (test first)
git stash apply stash@{1}

# Create a branch from a stash (clean recovery path)
git stash branch feature/header-hover stash@{1}

# Interactively stash only selected hunks from a changed file
git stash push --patch

# Drop a stale stash entry
git stash drop stash@{2}

# Clear the entire stash stack (irreversible)
git stash clear

NOTE: git stash pop fails with a merge conflict if the working tree has changes that overlap with the stash — in that case Git leaves the stash entry on the stack so you can resolve conflicts and then run git stash drop manually after the resolution is committed.