LinuxCommandLibrary

gc

Remove untracked git files

TLDR

Count nodes and edges in a file

$ gc [path/to/file.dot]
copy

Count only [n]odes
$ gc -n [path/to/file.dot]
copy

Count only [e]dges
$ gc -e [path/to/file.dot]
copy

Count [c]onnected components
$ gc -c [path/to/file.dot]
copy

Display help
$ gc -?
copy

SYNOPSIS

git gc [--aggressive] [--auto] [--no-auto] [--prune=<date>] [--no-prune] [-q|--quiet] [--force] [--keep-largest-pack] [--depth <n>] [--unpack-refs] [-v|--verbose]

PARAMETERS

--aggressive
    More thorough cleanup at cost of longer runtime

--auto
    Enable auto mode; exit if no work needed (default)

--no-auto
    Disable auto check; always run

--prune=<date>
    Prune loose objects older than date (default: 2 weeks)

--no-prune
    Skip pruning loose objects

-q, --quiet
    Suppress progress output

--force
    Force run despite auto check

--keep-largest-pack
    Reuse largest pack without repacking

--depth <n>
    Set delta compression depth for packs

--unpack-refs
    Don't repack refs into pack

-v, --verbose
    Enable verbose progress reporting

DESCRIPTION

The gc command typically refers to git gc, a maintenance utility in Git for cleaning up a local repository. It performs garbage collection by packing loose objects into packfiles, pruning unreachable objects, compressing reflogs, and repacking refs for efficiency.

This reduces repository disk usage and improves performance for operations like clone and fetch. By default, git gc runs automatically via hooks like post-merge and post-checkout if housekeeping criteria are met (e.g., too many loose objects). Manual invocation is useful for aggressive cleanup on large repos.

While not a standalone gc binary in core Linux tools, it is invoked as git gc and often aliased as gc in developer workflows. No standard gc exists in coreutils; confirm context if different.

CAVEATS

Frequent manual runs waste CPU; rely on auto. Largest-pack option may fail if pack is corrupt. Not for bare repos without caution.

DEFAULT BEHAVIOR

Runs if >6750 loose objects, >50 packs, or reflog >90% full. Packs refs unless --unpack-refs.

EXAMPLE

git gc --aggressive --prune=now
Deep cleanup, immediate prune.

HISTORY

Introduced in Git 1.5.0 (2007) as basic cleanup tool. Evolved with auto-detection in 1.6.0+, aggressive mode in 1.7.0+. Key for scaling Git in large projects like Linux kernel repo.

SEE ALSO

Copied to clipboard