LinuxCommandLibrary

git-pack-refs

Consolidate loose refs into packfiles

SYNOPSIS

git pack-refs [options] [<ref-pattern> ...]

PARAMETERS

-a, --all
    Pack all local refs in refs/ namespaces. Shows progress unless quiet.

--prune
    Remove loose refs after packing them. Default with --all.

--dry-run
    Simulate packing without changes or file modifications.

-q, --quiet
    Suppress output like 'Packing <ref>' messages.

DESCRIPTION

The git pack-refs command consolidates loose references (individual files in $GIT_DIR/refs/) into a single $GIT_DIR/packed-refs file. This reduces filesystem overhead, improving performance for repositories with many branches and tags.

Loose refs are normal files storing 40-byte SHA-1 hashes. Packed refs combine them into one sorted file with optional flags like 'peeled' for annotated tags (storing both tag and target object IDs).

By default, it packs specified refs without deleting loose versions. Use --prune to remove loose refs post-packing, reclaiming space. --all targets all local refs. It's low-level; git gc invokes it automatically during garbage collection.

Benefits include faster ref lookups and fewer directory entries, crucial for large repos. However, packed-refs requires atomic updates via locking, ensuring consistency.

CAVEATS

Does not pack reflogs or remote refs by default. Frequent manual use unnecessary; git gc automates it. Packed-refs locking prevents corruption but may contend in high-write scenarios.
Patterns like refs/heads/* supported; no args packs nothing.

PACKED-REFS FORMAT

Sorted file lines: [<flag> ]<SHA-1> <refname> [^{} for peeled]. Atomic append-only updates.

UNPACKING REFS

Use git unpack-refs [--prune] to restore loose refs if needed.

HISTORY

Introduced in Git ~1.4 (2006) for ref optimization. Evolved with support for peeled tags (v1.6+) and namespace handling.

SEE ALSO

Copied to clipboard