Full clone của large monorepo (Facebook-scale) có thể mất 30+ phút. CI/CD cần tối ưu.
Shallow clone — chỉ clone N commits gần nhất:
git clone --depth 1 https://github.com/org/repo
# Chỉ lấy latest commit, không có history
# Tốt cho: CI build, Docker build layer
# Trong GitHub Actions:
- uses: actions/checkout@v4
with:
fetch-depth: 1 # shallow
# fetch-depth: 0 = full history (cần cho semantic-release)Partial clone — clone repo nhưng defer downloading large blobs:
# Blobless clone: download trees nhưng defer blobs — phù hợp nhất cho CI
git clone --filter=blob:none https://github.com/org/repo
# Blobs tải về khi bạn thực sự checkout file đó (không phải "chỉ metadata")
# Treeless clone (filter=tree:0): không tải trees — checkout gần như không dùng được
# Chỉ dùng cho special cases (shallow inspection), không phải CI thông thường
git clone --filter=tree:0 https://github.com/org/repoSparse checkout — chỉ checkout 1 subdirectory của monorepo:
git clone --no-checkout https://github.com/org/monorepo
cd monorepo
git sparse-checkout init --cone
git sparse-checkout set apps/my-app packages/shared
git checkout mainCI/CD best practice: --depth 1 + --filter=blob:none + sparse checkout = clone time giảm 90% cho large monorepos.
Lưu ý: shallow clone làm git bisect và git log --all không hoạt động đầy đủ.
Full clone of a large monorepo can take 30+ minutes. CI/CD needs optimization.
Shallow clone — only clone the last N commits:
git clone --depth 1 https://github.com/org/repo
# Only fetches the latest commit, no history
# Good for: CI builds, Docker layer builds
# In GitHub Actions:
- uses: actions/checkout@v4
with:
fetch-depth: 1 # shallow
# fetch-depth: 0 = full history (needed for semantic-release)Partial clone — clone repo but defer downloading large blobs:
# Blobless clone: downloads trees but defers blobs — best for CI
git clone --filter=blob:none https://github.com/org/repo
# Blobs are fetched when you actually check out the file (not just metadata)
# Treeless clone (filter=tree:0): no trees downloaded — nearly unusable for checkout
# Only for special cases like shallow inspection, not regular CI
git clone --filter=tree:0 https://github.com/org/repoSparse checkout — only check out one subdirectory of a monorepo:
git clone --no-checkout https://github.com/org/monorepo
cd monorepo
git sparse-checkout init --cone
git sparse-checkout set apps/my-app packages/shared
git checkout mainCI/CD best practice: --depth 1 + --filter=blob:none + sparse checkout = 90% reduction in clone time for large monorepos.
Note: shallow clone breaks git bisect and git log --all because history is incomplete.