What is git stash?

Why Interviewers Ask This

Interviewers use this question to quickly assess whether a candidate has the foundational knowledge required for Git & GitHub development. It reveals whether you understand the building blocks that more complex concepts rely on.

Answer

git stash temporarily shelves (saves) changes you've made to your working directory and staging area so you can work on something else, then come back and re-apply them. Your working directory is cleaned to match the last commit. Commands: git stash / git stash push — stash all uncommitted changes (tracked files); git stash -u / --include-untracked — also stash untracked files; git stash -a / --all — also stash ignored files; git stash save "message" — stash with a descriptive name; git stash list — list all stashes (stash@{0} is most recent); git stash apply — re-apply the most recent stash (keeps stash in list); git stash pop — re-apply AND remove from stash list; git stash apply stash@{2} — apply a specific stash; git stash drop stash@{0} — delete a stash; git stash clear — delete all stashes; git stash branch feature — create a new branch from a stash. Common use case: you're mid-feature when an urgent bug comes in — stash your work, fix the bug, then pop the stash to resume.

Pro Tip

Before answering, structure your response: one-line definition → real-world analogy → concrete example from a project. This makes even complex Git & GitHub answers easy to follow.