git-repack - Linux


Overview

git-repack is a Git command used to compress a Git repository and optimize its performance. It reorganizes the objects stored in a repository, removing unnecessary objects and repacking the remaining objects more efficiently. This can significantly reduce the size of the repository and speed up Git operations, especially on large repositories.

Syntax

git repack [--[no-]unreachable] [--[no-]pack-objects] [--[no-]local] [--[no-]write-bitmaps] [--[no-]block-report] [--[no-]window-memory=<bytes>] [--[no-]depth=<depth>] [--temp-pack=<file>] [--pack-objects=<file>] [--] <packfile>...

Options/Flags

  • –[no-]unreachable: Prune unreachable objects before packing. Unreachable objects are objects that are not referenced by any commit, branch, or tag. Default: true
  • –[no-]pack-objects: Pack objects into a single packfile. If specified, is ignored. Default: false
  • –[no-]local: Pack only local objects. Default: false
  • –[no-]write-bitmaps: Write bitmaps for object storage. Default: true
  • –[no-]block-report: Disable block progress reporting. Default: false
  • –[no-]window-memory=: Set the memory limit for the window. Default: 256 MiB
  • –[no-]depth=: Limit the depth of the traversal. Default: 25
  • –temp-pack=: Use as a temporary pack for repacking. Default: .git/objects/pack/tmp-pack-XXXXXX
  • –pack-objects=: Pack objects into .

Examples

Repack a repository:

git repack

Repack a repository and prune unreachable objects:

git repack --unreachable

Pack objects into a custom packfile:

git repack --pack-objects=my-packfile.pack

Pack only local objects:

git repack --local

Common Issues

Repository size does not decrease after repacking: This can occur if there are too many unreachable objects in the repository. Use git gc --prune=now to remove them.

Packfile size exceeds file system limits: Adjust the --window-memory option to reduce the memory usage during packing.

Integration

Use with git-gc: git-repack can be used together with git-gc to optimize repository performance. git-gc performs a complete garbage collection, removing all unreachable objects and optimizing the repository structure.

Use with pre-commit hooks: git-repack can be integrated with pre-commit hooks to automatically repack the repository before committing changes. This can help ensure that the repository remains optimized.

Related Commands