LinuxCommandLibrary

git-prune-packed

Remove redundant, packed Git objects

SYNOPSIS

git prune-packed [-n | --dry-run] [-q | --quiet]

PARAMETERS

-n, --dry-run
    Perform a dry run: list objects that would be pruned without removing them

-q, --quiet
    Suppress all output except errors; do not list pruned objects

DESCRIPTION

The git prune-packed command removes loose objects from the .git/objects directory that are already stored within pack files. This cleanup is essential after running git repack, as repacking consolidates loose objects into efficient pack files, leaving redundant loose copies that waste disk space.

It scans the repository's pack files and deletes any loose objects whose content is fully contained within those packs. This process helps maintain a lean repository by eliminating duplicates.

Typically invoked manually or via maintenance scripts, it complements git gc, which automates packing and pruning. Use the -n option for a dry run to preview actions without changes. Output lists removed objects unless suppressed with -q.

Ideal for servers or large repos where space efficiency matters, but run sparingly as it requires scanning all packs.

CAVEATS

Only affects loose objects; does not touch pack files. May be redundant with git gc --prune=now. Requires read-write access to repository.

USAGE EXAMPLE

git repack -a -d
git prune-packed

Repacks all objects then prunes loose duplicates.

OUTPUT

Without -q, prints one line per pruned object: <sha1>.

HISTORY

Introduced in Git 1.0.0 (2005) as part of early repository maintenance tools. Evolved with Git's object storage; largely automated by git gc in modern versions (post-1.5).

SEE ALSO

Copied to clipboard