Large_Scale_Repos_and_Branches
Large Scale Repos and Branches
Managing massive repositories.
π Monorepo Challenges
graph TD
A[Large Monorepo] --> B[Slow Clone]
A --> C[Slow Checkout]
A --> D[Complex Dependencies]
A --> E[Many Contributors]
β‘ Faster Clone
Shallow Clone
git clone --depth 1 repo.git
Only latest commit.
Single Branch Clone
git clone --single-branch -b main repo.git
Only clone main branch.
Blobless Clone
git clone --filter=blob:none repo.git
Downloads structure without file contents. Fetches on demand.
Treeless Clone
git clone --filter=tree:0 repo.git
Most minimal clone. Fetches trees on demand.
π Sparse Checkout
Enable Sparse Checkout
git sparse-checkout init
Enables sparse checkout mode.
Set Paths to Include
git sparse-checkout set src/my-service shared/utils
Only checkout these paths.
Add More Paths
git sparse-checkout add tests/my-service
Adds more paths.
List Current Patterns
git sparse-checkout list
Shows what's included.
Disable Sparse Checkout
git sparse-checkout disable
Returns to full checkout.
π¦ Git LFS
Install LFS
git lfs install
Sets up LFS in repo.
Track Large Files
git lfs track "*.psd"
Tracks Photoshop files.
git lfs track "*.zip"
Tracks zip files.
View Tracked Patterns
cat .gitattributes
Shows LFS patterns.
List LFS Files
git lfs ls-files
Shows files in LFS.
πΏ Branch Management
List Remote Branches
git branch -r
Shows all remote branches.
Delete Merged Branches
git branch --merged main | grep -v main | xargs git branch -d
Cleans up merged branches.
Prune Stale References
git remote prune origin
Removes deleted remote branches.
π Repository Size
Check Size
git count-objects -vH
Shows repo size.
Find Large Files
git rev-list --objects --all | git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' | sort -k3 -n -r | head -20
Lists 20 largest files.
βοΈ Performance Config
Enable Commit Graph
git config --global core.commitGraph true
Speeds up history operations.
Fast Status
git config --global core.untrackedCache true
Caches untracked files.
Enable Multi-pack Index
git config --global core.multiPackIndex true
Faster pack operations.
π‘ Tips
CI Optimization
Use shallow clones in CI for speed.
Monorepo Tools
Consider Nx, Turborepo, or Bazel for monorepo management.
π Related
#git #monorepo #largescale #performance