stackademic

The leading education platform for anyone with an interest in software development.

Stash

Temporarily shelve uncommitted changes and restore them later

Overview

git stash saves your working directory and index changes without committing. Switch branches, pull updates, or handle urgent fixes—then reapply stashed work when ready.

Syntax / Usage

# Stash tracked changes
git stash
git stash push -m "WIP login form"

# Include untracked files
git stash -u

# List stashes
git stash list

# Apply most recent (keep stash)
git stash apply

# Apply and remove
git stash pop

# Apply specific stash
git stash apply stash@{2}

# Drop stash
git stash drop stash@{0}
git stash clear   # remove all

Examples

Switch branches with dirty working tree:

git stash push -m "half-done refactor"
git switch main
git pull
git switch feature/refactor
git stash pop

Stash only specific files:

git stash push -m "config only" -- package.json tsconfig.json

Common Mistakes

  • Forgetting stashed work exists—git stash list regularly
  • stash pop conflicts when codebase changed—resolve like a merge
  • Stashing secrets you did not mean to persist in .git internals
  • Assuming stashes are backed up remotely—they are local unless pushed to a special branch

See Also

commit branch merge remote