How to stash changes in Git

· Category: Git

Short answer

Run git stash to save your current uncommitted changes and revert the working directory to HEAD.

Steps

  1. Stash current changes:
git stash push -m "WIP on feature"
  1. List stashes:
git stash list
  1. Apply the latest stash:
git stash pop
  1. Apply without removing:
git stash apply stash@{0}

Tips

  • Stash is local and will not be pushed to remotes.
  • git stash -u includes untracked files.
  • Name your stashes with messages for easier identification.

Common issues

  • Forgetting about old stashes can lead to confusion; clean up with git stash drop.
  • Stash does not stash ignored files unless you use --all.