Lesson 52 +15 XP

Git Stash

Git Stash

git stash sets your changes aside temporarily so you can work on something else, then brings them back later.

The stash command

git stash

Your uncommitted changes are saved and your working directory becomes clean, matching the last commit.

Why stash?

  • You must switch branches but your work is not ready to commit.
  • You need a clean working tree before pulling or switching.
  • You want to set work aside and come back to it.

See your stashes

git stash list

Each stash is listed with an index like stash@{0}.

Bring changes back

git stash pop

This applies the most recent stash and removes it from the list.

Apply without removing

git stash apply

This applies the stash but keeps it in the list, handy if you want to apply it in multiple places.

Stash with a message

git stash push -m "WIP login fix"

TL;DR

  • git stash temporarily puts uncommitted changes aside.
  • git stash list shows saved stashes.
  • git stash pop restores and removes the latest stash.
  • git stash apply restores but keeps it.