Basic commands

bash
git stash push -m "wip: login form"   # save tracked changes
git stash push -u -m "wip"             # include untracked files
git stash list                         # show the stack
git stash show -p stash@{0}            # diff of a stash
git stash pop                          # apply latest and drop it
git stash apply stash@{1}              # apply without dropping
git stash drop stash@{0}               # delete a stash
git stash clear                        # delete all stashes

Pop vs apply

Use apply when you may need the stash again or when you are unsure it will apply cleanly. Use pop for the common case of restoring and discarding in one step.

CommandAppliesRemoves from stack
git stash popLatest stashYes, if apply succeeds
git stash applyAny stashNo
git stash apply stash@{n}Specific stashNo

What stash does not include

  • Untracked files, unless you pass -u (or -a to include ignored files).
  • Changes in submodules, by default.
  • Staged versus unstaged distinction, unless you use --keep-index or --staged.

A stash is local only. It is not pushed and does not survive a fresh clone. Do not use it as a backup.

Conflicts when applying

If the files changed since the stash was created, applying can conflict. Resolve them as usual; with pop, the stash is only dropped after a successful apply. If you abort, the stash remains.

bash
git stash apply
# conflicts in working tree
git status
# resolve, then optionally drop the stash
git stash drop

Recover a dropped stash

Dropped stashes are commits without a ref. git fsck --no-reflog can list dangling commits, and the stash commit is often identifiable by its message.

bash
git fsck --no-reflog | grep commit
# inspect candidates
git show <sha>
# restore
git stash apply <sha>

Recovery is best-effort and time-limited by Git's garbage collection. For long-lived work, commit to a branch instead.