Switching branches with uncommitted changes in the way is a common snag — git stash temporarily shelves those changes without committing them, so a branch switch can happen cleanly.
git status
# modified: index.html (not staged)
git stash
# Saved working directory and index state WIP on main: a1b2c3d Add README
git status
# nothing to commit, working tree cleangit stash pop
# Restores the most recent stash AND removes it from the stash list# Restore it but keep the stash entry too, for applying elsewhere
git stash applygit stash list
# stash@{0}: WIP on main: a1b2c3d Add README
# stash@{1}: WIP on feature-login: e5f6g7h Add form
git stash apply stash@{1} # apply a specific one, not just the most recentgit stash push -m "Half-finished login validation"git stash drop stash@{0}
# Discard every stash entry
git stash clearThe classic use case
A typical real use: mid-way through a change, an urgent bug needs fixing on main right now. git stash, switch to main, fix the bug, switch back, git stash pop — the half-finished work resumes exactly where it was left.