Git & GitHub Interview Question #48

What is git stash?

Remotes, Fetch, Pull, Push, Merge, Conflicts, Rebase & Stash Mid-Level Intermediate

Quick Interview Answer

git stash temporarily saves selected working-tree and index changes so you can return to a cleaner working state without creating a normal project commit. It is useful when unfinished work must be set aside briefly to switch branches or handle an urgent task.

Detailed Explanation

git stash temporarily saves selected working-tree and index changes so you can return to a cleaner working state without creating a normal project commit. It is useful when unfinished work must be set aside briefly to switch branches or handle an urgent task.

A stash should not become permanent storage for important work. Named commits on an appropriate branch are usually easier to understand and recover over the long term.

Code Example

git stash push -m "WIP interview page"

git stash list

# Reapply later
git stash pop