Optimize a Repository With git repack

Consolidate loose objects into a compact packfile.

macOSperformancegitcliLow risk
Run git repack -ad to rewrite packs and drop redundant loose objects.

01Command

Command
$ git repack -ad

02What it does

Repositories accumulate loose objects and duplicate packs; repacking consolidates them, reducing disk use and speeding up fetch and clone. It is a routine maintenance task that is easy to script across many repositories, unlike a single-repo GUI button.

03Risk

RiskLow risk
RequirementsGit 2.20+ (install with Homebrew or Xcode Command Line Tools)
CompatibilitymacOS with Git installed (Homebrew or Xcode Command Line Tools)
!Warning: Run it when no other git process is writing; concurrent operations can race with repacking.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

Last verified: 2026-10-13 · Category: Developer