Monorepo

2 snippets across 2 stacks - Git, TypeScript

GitGit

Sparse Checkout (Partial Clone)

Git · Advanced
Syntax
git sparse-checkout init --cone
git sparse-checkout set <dir1> <dir2>
Example
git clone --filter=blob:none --sparse https://github.com/large/monorepo.git
cd monorepo
git sparse-checkout set services/auth packages/shared

Note Only checks out specified directories from a large repo. Extremely useful for monorepos where you only need a small portion. --filter=blob:none avoids downloading file content you don't need.

TSTypeScript

Project References

TS · Configuration
Syntax
// tsconfig.json
{
  "references": [
    { "path": "./packages/core" },
    { "path": "./packages/api" }
  ]
}
Example
// Root tsconfig.json
{
  "files": [],
  "references": [
    { "path": "./packages/shared" },
    { "path": "./packages/server" },
    { "path": "./packages/client" }
  ]
}

// packages/server/tsconfig.json
{
  "compilerOptions": {
    "composite": true,
    "outDir": "./dist",
    "rootDir": "./src"
  },
  "references": [
    { "path": "../shared" }
  ]
}

// Build with: tsc --build
Output
// tsc --build only recompiles packages that changed

Note Project references enable incremental builds in monorepos. Each sub-project needs "composite": true. Build with tsc --build (or tsc -b) which understands dependency order. This dramatically speeds up type-checking in large codebases by skipping unchanged packages.

Frequently asked questions

How does Git handle monorepo?
This task is covered in 2 stacks on this page: Git, TypeScript. The "Sparse Checkout (Partial Clone)" snippet in Git uses `git sparse-checkout init --cone`.
Which command does the Git example use?
The "Sparse Checkout (Partial Clone)" snippet uses `git sparse-checkout init --cone`, from the Advanced section of the Git cheat sheet.
Which stacks cover "monorepo" on this page?
Git, TypeScript. Together they hold 2 copy-ready snippets for this task.
Is there anything to watch out for?
Yes. For "Sparse Checkout (Partial Clone)": Only checks out specified directories from a large repo. Extremely useful for monorepos where you only need a small portion. --filter=blob:none avoids downloading file content you don't need.