git stash lets you temporarily set aside uncommitted changes so you can switch to a different, more urgent branch and come back to your original work later without committing half-finished code.
While mid-way through feature-x, an urgent bug comes in; you run git stash, then git checkout -b hotfix/urgent-bug main, fix and push the bug, then git checkout feature-x and git stash pop to resume exactly where you left off.
git stash
git checkout -b hotfix/urgent-bug main
# fix and commit the bug
git checkout feature-x
git stash popA concise interview answer is
I'd stash my uncommitted changes with git stash, then branch off for the urgent task from the correct base. Once that's handled, I switch back to feature-x and run git stash pop to restore exactly where I left off.
Last updated: 11 November 2026
Previous question: How do you revert a commit in Git?
Next question: Merging feature-y into main gives a conflict in abc.java. How do you resolve it?