CommandGit

Stash and restore changes

Shelves uncommitted changes, including untracked files, onto a labeled stack so you can switch branches with a clean working tree.

Last updated

Commandgit
git stash push -u -m "wip"

How it works

git stash push saves every uncommitted change to tracked files (staged and unstaged alike) onto a stack and resets the working tree to match HEAD, freeing you to switch branches, pull, or check out something else without committing half-finished work. -u extends that to untracked files too, which plain git stash otherwise skips entirely — easy to forget and lose track of. -m "wip" attaches a readable label instead of the generic "WIP on branch" name every unlabeled stash gets, which becomes impossible to tell apart once you have more than one.

To bring the changes back, run git stash pop — it reapplies the most recent stash and removes it from the stack in the same step, restoring the working tree to exactly where you left off.

Watch out for

  • git stash pop can conflict, just like a merge, if the working tree has changed since you stashed — resolve the conflicts by hand, and note the stash entry stays on the stack until you manually git stash drop it (pop only removes it automatically on a clean, conflict-free apply).
  • Use git stash apply instead of pop if you want to reapply the same stash to more than one branch, since apply leaves it on the stack afterward instead of consuming it.
  • Stashes live only in your local clone — they're never pushed, fetched, or visible to collaborators — and git stash clear deletes every stash at once with no confirmation, so check git stash list first if you're not sure what's on the stack.

Related in Commands