Skip to main content
RunBook Academy

Git, CI/CD & GitOpsCII · Large Repository PerformanceDiscipline

Repository design discipline — prevention versus cure

Intermediate⏱ ~22 mingit

What you'll learn

  • Apply the four disciplines at repo creation: gitignore, hooks, attributes, push protection
  • Identify the architecture choices (monorepo, multi-repo, hybrid) and their performance implications
  • Recognise when a forced history rewrite is the only fix and how to plan one
  • Document the prevention choices in the team onboarding runbook

Prerequisites

Verified against Git 2.55.x teaching target; 2.40+ minimum · GitHub Actions continuous service; Aug 2026 documentation baseline · Argo CD v3.5.x teaching target; v3.0+ minimum · Flux v2.9.x · Sigstore Cosign v3.1.x · SLSA v1.2 · OCI Distribution Specification v1.1 · Git LFS v3.7.1 · Kubernetes (cross-course target) 1.36.x

Not yet marked complete on this device.

Performance is cheaper at repo creation than retrofitted. Four preventive disciplines: .gitignore, pre-commit hooks, .gitattributes, push protection. The cure is a forced history rewrite that breaks every pinned consumer.

The four disciplines

  1. .gitignore. Match dist/, build/, node_modules/, target/, *.bin.
  2. Pre-commit hooks. check-added-large-files, check-merge-conflict, check-yaml.
  3. .gitattributes. For LFS patterns.
  4. Push protection. GitHub/GitLab/gitleaks.
flowchart LR
    A[repo create] --> B[".gitignore"]
    A --> C[".gitattributes"]
    A --> D["pre-commit hooks"]
    A --> E["push protection"]
    B --> F["prevention"]
    C --> F
    D --> F
    E --> F
    F --> G["no rewrite"]

Prevention is four small steps; cure is a forced rewrite that breaks pinned consumers.

Architecture choices

  • Monorepo. Cost: large packfile, slow clone. Mitigation: partial + sparse; --depth 1 for CI.
  • Multi-repo. Cost: cross-repo refactoring. Mitigation: submodules or tags.
  • Hybrid. Monorepo with submodules. Most common in production.

Choice depends on team and release cadence.

When a rewrite is the only fix

  • Binary growing. Fix: git lfs migrate.
  • Credential committed. Fix: git filter-repo and rotation (PR forks keep old commits).
  • Repo split. Fix: git filter-repo --target with subtree filter.

Each rewrite: re-sign tags, notify consumers.

Onboarding runbook

# Onboarding

1. Copy `.gitignore` from `github/gitignore`.
2. Copy `.pre-commit-config.yaml`.
3. Add `.gitattributes`.
4. Enable push protection.
5. Branch protection on `main`.
6. Document architecture.

Six steps, ~30 minutes; prevent rewrites costing 30 engineer-days.

Production discipline

  1. Apply the four disciplines at repo creation.
  2. Document the architecture choice.
  3. Plan rewrites carefully.
  4. Audit any merge from outside the discipline.

Cross-course references

  • Linux for Production Sysadmins Part XXVI: layout discipline.
  • Ansible for Production Sysadmins Part XXXVII: monorepo role layout.
  • Terraform for Production Sysadmins Part IX: state version discipline.

Quiz

Knowledge check · 4 questions

  1. Q1. A new repo is created. Which four must be at the first commit to prevent forced history rewrites later?

  2. Q2. Adding a `.gitignore` rule years after the offending directory was first committed removes it from the next clone.

  3. Q3. Name the three situations that force a history rewrite, and the two commands that perform one.

  4. Q4. Recommend the day-one runbook for a new Terraform monorepo, and explain why each step prevents a rewrite.

    Team M: new Terraform monorepo for 30 services. Avoid rewrites later.

Passing score: 75%. Answers are checked in this browser.