Skip to content
rajin

16Stash, shelving and worktrees

core25–30 minHandbook pp. 37–38 Not started

Warm-up · from “Tags and revision syntax”

What does HEAD~3 follow?

No notes: write what you remember, then check. Recalling before reading is what makes it stick.

The problem

A production bug interrupts unfinished work. Should you stash changes, create a worktree or use your IDE's shelf?

After this lesson you can

  • Inspect stash parents.

  • Compare interruption strategies.

  • Create and remove an independent worktree.

Key terms

Full glossary

Say what each term means, then open it to check.

  • HEAD · from lesson 14

    Current symbolic branch reference or detached commit identity.

  • Index · from lesson 9

    Prepared path-to-object entries, plus metadata and conflict stages.

  • Commit · from lesson 7

    Object identifying a root tree, parent(s), metadata and message.

  • Ref · from lesson 3

    Name identifying an object; branch refs usually identify commits.

  • Reflog · preview, covered in lesson 28

    Local log of ref updates when enabled.

Visual mental model

  1. HEAD (base)
  2. Index Iparent: HEAD
  3. Stash Wparents: HEAD, I
A normal stash has two parents; the Index commit also has HEAD as its parent.

Build the mental model

A normal stash creates an Index snapshot commit I with parent HEAD, then a working snapshot commit W with parents HEAD and I. With -u or -a it can include an additional untracked/ignored snapshot parent. refs/stash identifies the latest entry; its reflog tracks older entries. stash apply keeps the entry; pop drops it only after a successful application. --index attempts to restore staged state too.

Under the hood

A worktree provides another checkout with its own HEAD and Index while sharing objects and ordinary branch refs. By default Git prevents the same branch from being checked out simultaneously in two worktrees. IDE shelving generally stores patches or IDE-managed data; location, portability and conflict handling depend on the IDE. Git has no native git shelve. Worktrees suit parallel work; stash suits short context switches; committed WIP gives a named durable state.

Common mistake · important nuance

Ordinary stash does not include untracked files unless requested. Inspect stash contents and avoid assuming it is a backup. Worktree files still consume disk space.

Move between parts freely. Completion counts only what you verify and answer.