# git repack: Usage, Options & Common CI Errors

> git repack combines loose objects and packs into fewer, tighter packfiles. Reference for -a, -d, -A, and the memory and disk errors on large repos in CI.

Source: https://latchkey.dev/learn/command-reference/git-repack  
Updated: 2026-06-25

git repack consolidates a repository’s objects into fewer, more efficient packfiles.

Repacking shrinks a bloated repo and speeds up object access. The common -a -d combination rewrites everything into one pack and removes the now-redundant ones.

## What it does

git repack creates new packfiles from existing objects, optionally folding all packs into one and deleting the originals, improving delta compression and lookup speed.

## Common usage

```Terminal
git repack -a -d
git repack -A -d                # keep unreachable objects loose
git repack -a -d --depth=50 --window=250
git repack -d -l                # local objects only
```

## Options

| Flag | What it does |
| --- | --- |
| -a | Pack all objects into a single pack |
| -A | Like -a but keep unreachable objects loose |
| -d | Delete redundant packs afterward |
| --depth / --window | Tune delta compression |
| -l | Pack only local objects (skip alternates) |

## Common errors in CI

fatal: Out of memory during delta compression on huge repos - lower --window/--depth or pack.threads, and ensure enough free disk for the new pack to be written before the old ones are deleted. Running repack -d while another git process reads the repo can race; serialize it.

## Using this in CI

CI checkouts are shallow and detached by default, which changes the answer this command gives you. Commands that read history, branch names, or tags need the checkout configured for it.

```.github/workflows/ci.yml
- uses: actions/checkout@v4
  with:
    fetch-depth: 0   # history, tags, and git describe all need this

- run: |
    git rev-parse --is-shallow-repository   # expect false
    git rev-parse --abbrev-ref HEAD          # prints HEAD when detached
```

> `git rev-parse --abbrev-ref HEAD` returns the literal string `HEAD` on a detached checkout rather than a branch name. On GitHub Actions read `github.ref_name` instead; the git command cannot know what it was checked out for.

## FAQ

### git repack: Usage, Options & Common CI Errors?

Repacking shrinks a bloated repo and speeds up object access. The common -a -d combination rewrites everything into one pack and removes the now-redundant ones.

### What it does?

git repack creates new packfiles from existing objects, optionally folding all packs into one and deleting the originals, improving delta compression and lookup speed.

### Common errors in CI?

fatal: Out of memory during delta compression on huge repos - lower --window/--depth or pack.threads, and ensure enough free disk for the new pack to be written before the old ones are deleted. Running repack -d while another git process reads the repo can race; serialize it.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
