Git stash is one of the most useful but underused Git features for WordPress developers. It lets you temporarily save uncommitted changes to a local stack (the “stash”) and restore a clean working directory, without committing half-finished work. The classic scenario: you are in the middle of developing a new feature in your WordPress theme, and a client reports an urgent bug on the live site. You cannot commit your half-finished feature, and you cannot check out the main branch with uncommitted changes blocking the switch. git stash saves all your changes, you switch to main, fix the bug, push, and then git stash pop restores your work exactly where you left off. The default git stash command stashes tracked modified files and tracked new files — but not untracked new files unless you add -u (or --include-untracked), and not ignored files unless you add -a (or --all). You can have multiple stash entries and apply them selectively with git stash apply stash@{2}. Giving stashes a descriptive name with git stash push -m “description” is essential when you accumulate several entries. Stashes can also be converted to branches with git stash branch — useful when the stashed changes conflict with current HEAD and you want to resolve them properly. Combine this with the Gitflow branching guide and Git hooks deployment guide for a complete Git workflow.
Problem: You need to switch branches or pull changes on an urgent fix while you have uncommitted work in progress in your WordPress theme, without losing your changes or committing incomplete code.
Solution: Use the following Git stash commands in your terminal:
# ── Basic stash workflow ──────────────────────────────────────────────────────
git stash # stash tracked changes (modified + staged)
git stash -u # also include untracked new files
git stash -m "WIP: new card component" # give the stash a descriptive name
git stash list # see all stash entries
# stash@{0}: On main: WIP: new card component
# stash@{1}: On feature/checkout: half-done checkout flow
git stash pop # apply the most recent stash and remove it
git stash apply # apply without removing (keeps stash entry)
git stash apply stash@{1} # apply a specific stash entry
git stash drop stash@{0} # delete a specific stash entry
git stash clear # delete ALL stash entries (irreversible!)
# ── Stash only specific files ─────────────────────────────────────────────────
git stash push -m "Only header changes" wp-data/themes/hello_admin/header.php
# ── Convert a stash to a branch (useful for conflict resolution) ──────────────
git stash branch feature/stashed-work stash@{0}
# Creates a new branch from the commit where stash was created,
# applies the stash, and drops the stash entry on success
# ── Show what is in a stash ───────────────────────────────────────────────────
git stash show stash@{0} # show changed files
git stash show -p stash@{0} # show full diff
# ── Typical urgent-fix workflow ───────────────────────────────────────────────
# 1. Stash your WIP
git stash -u -m "WIP: card redesign"
# 2. Switch to main and pull
git checkout main && git pull origin main
# 3. Create hotfix branch, fix bug, push
git checkout -b hotfix/broken-checkout
# ... fix ...
git add -A && git commit -m "fix: checkout total not updating"
git push origin hotfix/broken-checkout
# 4. Return to your feature and restore WIP
git checkout feature/card-redesign
git stash pop
NOTE: git stash pop applies the stash and removes it from the list — if the apply causes a merge conflict, Git leaves the stash entry intact so you do not lose your work. After resolving conflicts manually (git add the resolved files), run git stash drop to remove the stash entry manually. Never use git stash clear casually — it permanently deletes all stash entries with no undo. Stash entries are not pushed to the remote repository; they exist only in your local .git directory, so they are lost if you delete and re-clone the repository.