Skip to content
rajin

27Reachability and garbage collection

advanced25–30 minHandbook pp. 59–60 Not started

Warm-up · from “Packfiles and delta compression”

What is a pack index for?

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

The problem

After deleting a branch, why can its commits still exist? What determines when Git may remove them?

After this lesson you can

  • Trace reachability from refs.

  • Distinguish unreachable from dangling.

  • Explain collection and expiration limits.

Key terms

Full glossary

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

  • Reachability · new in this lesson

    Whether an object can be reached by traversing links from roots.

  • 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.

  • Tree · from lesson 6

    Directory snapshot mapping names, modes and object IDs.

  • 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. Ref
  2. reachable tip
  3. parent
  4. tree
  5. blob
  6. no rootunreachable candidate

Build the mental model

An object is reachable when it can be reached from a root by following references: commit parents and root trees, tree entries and tag targets. Git's maintenance also considers roots such as reflogs and the Index. Removing a branch can make some objects unreachable from ordinary refs, but a reflog or another reference may preserve them. An unreachable object is not necessarily dangling: dangling usually means no other inspected object points to it.

SimulationReachability from roots

A simplified model for building intuition. It does not read your sandbox; use the terminal for real behaviour.

Under the hood

Garbage collection can repack reachable data and eventually prune unreachable data. Defaults commonly include 90 days for reflog entries, 30 days for entries unreachable from the current tip, and a two-week grace period for pruning eligible unreachable objects. These are configurable rules, not a recovery guarantee. Modern Git may retain unreachable objects in cruft packs. Never run aggressive prune or reflog expiry while attempting recovery.

Common mistake · important nuance

A branch deletion is not an immediate object deletion. Conversely, Git is not a permanent archive of every abandoned object.

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