Next.js starter your AI actually understands. Ship internal tools in days not weeks. Pre-order $199 $499 → [Get it now]

How to optimize Git performance

Git performance degrades over time in large repositories with thousands of commits, large files, and many contributors — slow git status, git fetch, and git log operations indicate the repository needs maintenance. As the creator of CoreUI with 25 years of open-source development experience, I regularly optimize the CoreUI repository and contributor workflows to keep Git operations fast as the codebase grows. The primary tools are git maintenance for automated upkeep, git gc for manual cleanup, and repository configuration settings that enable performance optimizations. Most optimizations are one-time setup or periodic maintenance commands that dramatically improve day-to-day performance.

Enable background maintenance to keep the repository optimized automatically.

# Register the repo for background maintenance (runs automatically)
git maintenance start

# This sets up:
# - prefetch: fetch objects every hour
# - gc: garbage collection weekly
# - commit-graph: update commit graph daily
# - loose-objects: pack loose objects daily
# - incremental-repack: consolidate packs daily

git maintenance start schedules background tasks that keep the repository objects organized. After running it once, Git handles cleanup automatically without you needing to remember to run git gc.

Run Manual Garbage Collection

Compact the repository and remove unreachable objects.

# Standard garbage collection
git gc

# Aggressive - more thorough but slower
git gc --aggressive --prune=now

# Check repository size before and after
git count-objects -vH

git gc packs loose objects, removes unreachable objects, and consolidates pack files. --aggressive uses more CPU for better compression. --prune=now removes unreferenced objects immediately instead of waiting the default 2-week grace period.

Speed Up git status with Filesystem Monitor

Enable fsmonitor for large repositories on supported systems.

# Enable filesystem monitor (macOS/Windows with fsmonitor-watchman)
git config core.fsmonitor true
git config core.untrackedCache true

# Or use the built-in fsmonitor daemon (Git 2.36+)
git config core.fsmonitor true
git fsmonitor--daemon start

Without fsmonitor, git status scans every file in the working tree. With it, the OS notifies Git which files changed since last check, making git status near-instantaneous in large repositories.

Write Commit Graph for Faster History Traversal

Pre-compute commit graph data to speed up git log and git merge-base.

# Write the commit graph
git commit-graph write --reachable --changed-paths

# Verify it was written
ls .git/objects/info/

# Configure automatic graph updates
git config fetch.writeCommitGraph true

The commit graph caches commit reachability data, making git log --graph, git merge-base, and other ancestry queries significantly faster. --changed-paths adds bloom filters for faster path filtering.

Shallow Clone and Partial Clone for CI/CD

Speed up clones in CI pipelines.

# Shallow clone - only latest commit (fastest, no history)
git clone --depth 1 https://github.com/org/repo.git

# Partial clone - skip large blobs
git clone --filter=blob:none https://github.com/org/repo.git

# In CI: fetch only the branch being built
git fetch origin main --depth=1
git checkout main

Shallow clones are ideal for CI/CD where you only need to build and test the latest commit. --depth=1 downloads one commit instead of the full history, reducing clone time from minutes to seconds for large repositories.

Best Practice Note

For CoreUI contributor workstations, we recommend running git maintenance start once after cloning to enable automatic optimization. For large files like images, videos, or binaries, use Git LFS to store them outside the main repository — Git performs poorly when large binary files are committed directly. See how to use Git LFS for setting up LFS for binary file management.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author