Skip to content

The Stash

The stash is git's drawer: you sweep the current mess of changes into it, the tree comes back clean, and you deal with whatever interrupted you — a branch to check, an urgent fix — before sweeping the mess back out. This chapter works the drawer in lazygit: the quick stash, the five flavours behind the options menu, and the three different ways work comes back out. The outcome: you can park work mid-thought, name it so future-you knows what it was, and restore it by applying or popping, knowing exactly what each does to the drawer's contents.

Start in the fixture (chapter 4): three changes in the tree, nothing committed since the summer walk.

The quick stash: s

Press s in the Files panel. Before anything moves, a small editor asks for a message — the lab typed WIP walk notes. Enter, and it is done (transcript lazygit-lab/transcripts/t06-stash.txt). The command log keeps the plain truth:

git stash push -m "WIP walk notes"

Look at what changed:

  • The Files panel now holds one row: ?? winter-walk.txt. The tracked changes — the staged shopping list and the modified summer notes — are in the drawer. The untracked file was left where it lay: a plain stash takes tracked work only, and winter-walk.txt, which git has never been told about, stays visible. Remember this on the day a "clean" tree still shows a file; the third flavour below exists for it.
  • The Stash panel, empty all this time, now reads On main: WIP walk notes — your message, prefixed with the branch you stashed from — and its border counts "1 of 1".

The message is worth the three seconds. A stash list full of git's default "WIP on main: 5beda9cf Add summer walk notes" is a drawer of unlabelled jars; the lab's own entry, made with the default, would have read exactly that. Name the work as you park it.

The options menu: S

Capital S opens the menu the plain key skips — five flavours, each with its letter (from the lab's screen):

  • a — Stash all changes. The plain stash above.
  • i — Stash all changes and keep index. The tree is swept but your staged set is restored to the index afterwards — for parking the unstaged half of your work while keeping a commit half-assembled.
  • U — Stash all changes including untracked files. The whole sweep, winter-walk.txt and all: the tree ends truly empty.
  • s — Stash staged changes. Only what is in the index goes in the drawer.
  • u — Stash unstaged changes. Only the working-tree half goes; the index keeps its contents.

These are git stash push's own options (--keep-index, --include-untracked, --staged, --keep-index's unstaged twin), wearing sentences instead of flags, each with a description in the box below the menu as you highlight it — the same self-describing pattern as chapter 10's menus.

Getting work back: the Stash panel

Press 5 to focus the Stash panel. The selected entry's diff fills the main panel — both files, the whole content of the drawer slot — so you restore with your eyes open. The hint bar offers three verbs, and they are not synonyms:

  • Space — Apply. The changes are laid back onto the tree, and the entry stays in the drawer. Apply twice and you will meet the same changes twice; apply is for borrowing the work, or for when you want the safety of the copy remaining.
  • g — Pop. The changes are laid back and the entry is dropped — behind a confirmation ("Are you sure you want to pop this stash entry?"), because pop is apply with no copy left. The lab popped its WIP walk notes and verified with git afterwards: git stash list empty, and both tracked changes back in git status, staged state and all.
  • d — Drop. The entry is deleted without applying it. The changes exist only in that entry; dropping is discarding, chapter 10's rules apply, and the confirmation is the last exit.

One behaviour worth knowing before it surprises you: applying or popping onto a tree that has moved on can produce a merge conflict, exactly as git stash apply can — the stash is an old state of the files meeting a new one. Chapter 11's conflict view is the tool for that meeting, and it works the same there.

When the drawer is the wrong tool

The stash is for minutes and hours: an interruption, a branch hop (chapter 6's stranded traveller ends here), a quick experiment you might throw away. For work that matters across days, a branch with real commits is the better drawer — it has a name that means something, it shows in history, and it cannot be dropped by one tired d. The lab's rule of thumb, offered as this chapter's check: if you would grieve its loss, it deserves a commit. Chapter 1's rule says the rest.