Skip to content
BENIBIX Learn

Git Stash

Development🔀 Version ControlBranches and History

Also known as Stash

Put your changes to one side for now. Then bring them back when you are ready.

Think of it like

Think of it like toys in a drawer while you eat. After dinner, you take them out again.

Example

Jack is halfway through a change when a bug report comes in. He stashes his work, fixes the bug on main, then pops the stash.

Why it matters

You can drop what you are doing for an urgent job. No messy half-done commit is needed.

Definition

Git stash puts your unsaved changes aside and leaves your files clean. It is useful when you need to switch branches but are not ready to commit. The changes go onto a pile, newest on top. Later, git stash pop puts them back where you left off. A stash stays on your computer only and is never pushed.

Example code

console
$ git stash
Saved working directory and index state WIP on main: 26b91bd Blue greeting
$ git stash list
stash@{0}: WIP on main: 26b91bd Blue greeting
The half-done work is set aside, and the files are clean again.

Common mistake

Stashing and forgetting. Old stashes pile up, and nobody remembers what is in them.

Key takeaways

  1. 1
    Set work aside. Changes leave your files for now.
  2. 2
    Pop to get back. git stash pop restores them.
  3. 3
    Local only. A stash is never pushed.

Learn it properly