Skip to content

Instantly share code, notes, and snippets.

@ScottKillen
Last active August 17, 2024 15:05
Show Gist options
  • Save ScottKillen/5fbbed7e50d0598e6ccdc535d9fae38c to your computer and use it in GitHub Desktop.
Save ScottKillen/5fbbed7e50d0598e6ccdc535d9fae38c to your computer and use it in GitHub Desktop.
Shell script to optimize a git repo for many files
#!/bin/sh
# Enable Git optimizations for repositories with many files.
git config feature.manyFiles true
# Update the index format to version 4 for better performance with large repositories.
git update-index --index-version 4
# Enable filesystem monitoring to speed up `git status` and similar commands.
# This uses the built-in fsmonitor on supported systems, reducing the need to scan the entire working directory.
git config core.fsmonitor true
# Enable caching of untracked files to speed up commands like `git status`.
# This avoids repeatedly scanning for untracked files.
git config core.untrackedCache true
# Enable commit graph for faster operations like `git log`, `git blame`, and `git rebase`.
# This precomputes and stores a graph of commits.
git config core.commitGraph true
# Automatically update the commit graph during `git fetch`, keeping it in sync with the latest changes.
git config fetch.writeCommitGraph true
# Optional: Enable sparse-checkout if working with very large monorepos.
# This allows you to check out only a subset of the repository.
# git sparse-checkout init --cone
# git sparse-checkout set <desired-directory>
# Optional: Enable parallel fetch and clone operations to speed up these processes.
# git config --global fetch.parallel 4
# Optional: Set the pack compression to a lower level (faster) during fetch and push operations.
# This is useful in very large repositories. Not recommen ded for development!
# git config pack.threads "1"
# git config pack.windowMemory "100m"
# Optional: Adjust the garbage collection settings to run less frequently.
# This prevents slowdowns during frequent commits or fetches.
# git config gc.auto 1000
# git config gc.autoPackLimit 1000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment