Q18 of 40 · Git
How does `git stash` work, and what are the common pitfalls of using it in a team QA workflow?
Short answer
Short answer: `git stash` saves dirty working tree and index to a stack, letting you switch context cleanly. Pitfalls: stashes are local (not pushed), easy to forget, don't stash untracked files by default, and the stack can grow stale.
Detail
git stash captures the current working tree diff and staged changes, then restores the working tree to HEAD, giving you a clean state to switch branches or pull. Stashes are stored in refs/stash as special commits and live only in your local repository — they are never pushed.
Common operations: git stash push -m "WIP: fix auth header" creates a named stash (much easier to identify later than the default "WIP on branch…"). git stash list shows the stack. git stash pop applies the most recent stash and drops it; git stash apply stash@{2} applies without dropping (useful if you want to apply to multiple branches).
Pitfalls in QA workflows: (1) Untracked files are not stashed unless you pass -u or --include-untracked — new test resource files will be left behind. (2) Stashes pile up over weeks and become mystery items that nobody dares delete. (3) git stash pop on a branch with conflicts leaves a mess; it's safer to use git stash branch <new-branch> to apply the stash onto a fresh branch. (4) Stash is local — if you need to carry WIP to another machine, commit with git commit -m "WIP", push, then reset later.
// EXAMPLE
# Save current WIP with a descriptive name
git stash push -m "WIP: flaky retry logic in OrderApiTest"
# Also stash untracked files (new test fixtures, etc.)
git stash push -u -m "WIP: add new schema fixtures"
# List all stashes
git stash list
# stash@{0}: On feature/retry: WIP: add new schema fixtures
# stash@{1}: On feature/retry: WIP: flaky retry logic
# Apply + drop most recent stash
git stash pop
# Apply a specific stash without dropping it
git stash apply stash@{1}
# Apply stash onto a new branch (avoids conflicts with current branch)
git stash branch fix/retry-logic stash@{1}
# Drop a specific stash
git stash drop stash@{0}
# Nuke all stashes (destructive — confirm first)
git stash clear