git Distributed version control system, created by Linus Torvalds

Stashing

git stash shelves uncommitted changes — both staged and unstaged — onto a stack, resetting your working directory to match HEAD, so you can switch tasks (e.g. to fix an urgent bug on another branch) without committing unfinished work.

Basic usage

git stash                        # stash tracked changes, staged + unstaged
git stash push -m "wip: parser"  # stash with a descriptive message
git stash list                   # show the stash stack
git stash pop                    # reapply the most recent stash and remove it
git stash apply                  # reapply the most recent stash, keep it in the list
git stash drop                   # delete the most recent stash without applying it
git stash clear                  # delete every stash

Working with a specific stash

The stack is indexed stash@{0} (newest) upward:

git stash show stash@{1}         # show summary of a specific stash
git stash show -p stash@{1}      # show its full diff
git stash apply stash@{1}        # apply a specific (non-latest) stash
git stash drop stash@{1}         # drop a specific stash

Useful options

git stash -u          # also stash untracked files
git stash -a          # also stash ignored files
git stash push -- path/to/file    # stash changes to one path only
git stash branch new-branch       # create a branch from a stash and apply it there

git stash branch is the safe option when applying a stash would conflict with how the current branch has moved on — it checks out a new branch from the commit the stash was originally based on, then applies the stash there.

A stash is stored as regular Git commits (under refs/stash), not magic — which is also why it survives things like git gc less reliably than a real branch. Don’t treat the stash as long-term storage for work you care about; commit to a branch instead if you’ll need it more than a day or two.