How do you stash uncommitted changes in Git?

Temporarily shelve work-in-progress changes with git stash so you can switch branches with a clean working tree.

GitVersion Control

Overview

Stashing lets you save unfinished work without committing it, so you can switch branches or pull updates and come back to your changes later.

Key Points

  • •`git stash` saves tracked modified files. Add `-u` to also stash untracked files.
  • •`git stash list` shows all saved stashes.
  • •`git stash pop` applies the most recent stash and removes it from the stash list.
  • •`git stash apply` applies the stash but keeps it in the list (useful for applying to multiple branches).
  • •Give stashes a name with `git stash push -m "message"` to find them easily later.

Examples

Stash current changes and get a clean working tree

bash
git stash

Saves staged and unstaged changes to tracked files.

Stash including untracked (new) files

bash
git stash -u
# or
git stash --include-untracked

List, apply, and drop stashes

bash
git stash list
# stash@{0}: WIP on main: a1b2c3d fix header
# stash@{1}: WIP on main: 9f8e7d6 add login

git stash pop            # apply latest stash, remove from list
git stash apply stash@{1} # apply a specific stash, keep it in list
git stash drop stash@{1}  # delete a specific stash

Save a named stash for easier identification

bash
git stash push -m "half-done payment form"

Pro Tip

Stash is not a substitute for committing. For work you might need across different branches or sessions, commit with a WIP message you can always amend or squash it later. Stashes are easy to forget and lose.