2.1 · The version-control map
Definition. A version control system (VCS) records changes to files over time so any prior state can be reconstructed, compared, merged, or attributed.
| Tool | Model | Where it shines (2026) | Share* |
|---|---|---|---|
| Git (Linus Torvalds, 2005) | Distributed, content-addressed | Universal default; vast ecosystem. | ~94% |
| Mercurial (hg) | Distributed, simpler UX than Git | Mozilla & Meta (largely on Sapling now). | ~1% |
| Subversion (SVN) | Centralised | Legacy enterprise, large binaries. | ~2% |
| Perforce / Helix Core | Centralised, file-locking | AAA game studios, EDA, huge binary assets. | ~1% |
| Fossil (D. Richard Hipp) | Distributed + bug tracker + wiki | SQLite project; self-contained single binary. | <1% |
| Sapling (Meta, 2022) | Mercurial-derived, Git-compatible | Massive monorepos, friendlier UX. | <1% |
| Jujutsu / jj (Google, 2023) | Git-compatible, snapshot-based, Mercurial-influenced | Power users who want immutable history & auto-rebase. | rising |
*Approximate developer-survey shares (Stack Overflow, JetBrains 2024–25); rounded.
2.2 · Git internals — the four object types
Definition. Git is a content-addressed key-value store: each object is hashed with SHA-1 (transitioning to SHA-256), and the hash is the primary key. Everything else (branches, tags, history) is a pointer graph above this store.
| Object | What it stores |
|---|---|
| blob | File contents — just bytes, no name. |
| tree | A directory: a list of (mode, name, blob/tree hash) entries. |
| commit | A snapshot pointer: tree + parent(s) + author + committer + message. |
| tag (annotated) | A named, signed pointer to any object (usually a commit). |
- DAG — commits form a Directed Acyclic Graph via their parent pointers. Merges have multiple parents.
- refs — human-readable names (
refs/heads/main,refs/tags/v1.0) that point at commits. - HEAD — symbolic ref pointing at the currently checked-out branch.
- index / staging — a binary file (
.git/index) listing the tree thatgit commitwould record. - pack files — delta-compressed bundles of objects on disk (
.git/objects/pack). - reflog — per-ref local history of where HEAD/branches pointed; survives most "dataloss" incidents.
# peek at a commit object as Git stores it
git cat-file -p HEAD
# list every reachable object
git rev-list --objects --all | head
2.3 · Branching strategies compared
| Strategy | Origin | Batch size | Best for |
|---|---|---|---|
| Trunk-Based Development | Paul Hammant; long-standing Google/FB practice | Tiny (hours) | CI/CD orgs aiming for Elite DORA. |
| GitHub Flow | GitHub blog (Scott Chacon, 2011) | Small (days) | SaaS, single-environment products. |
| GitLab Flow | GitLab (2014) | Small + environment branches | Products with staging/prod gates. |
| Git-Flow | Vincent Driessen, 2010 | Large (weeks) | Versioned/boxed software with multiple supported releases. |
| Release Train | SAFe, Spotify | Time-boxed | Big orgs that must align dozens of teams to a cadence. |
| Stacked PRs | Phabricator, Graphite, Sapling | Tiny + dependent | Long, decomposable refactors. |
2.4 · Trunk-based development deep dive
Definition. Trunk-Based Development (TBD) is a branching model in which all developers integrate to a single mainline branch (main) at least daily; branches, if used at all, live for hours.
- Short-lived branches — < 1 day; merge or delete.
- Feature flags hide unfinished work in production (LaunchDarkly, Unleash, Flagsmith, OpenFeature spec).
- Pre-commit hooks (e.g.
pre-commit, lefthook, Husky) keep the mainline green. - Branch-by-Abstraction for risky refactors — introduce an abstraction layer, swap implementations behind it.
- Required green build before merge; merge-queues (GitHub Merge Queue, Mergify, Aviator, Trunk.io) batch and re-test.
2.5 · Stacked diffs
Definition. A stacked diff workflow breaks a logical change into a chain of small, dependent commits — each reviewed and landed independently — instead of one mega-PR.
| Tool | Backed by | Notes |
|---|---|---|
| Phabricator / Phorge | Facebook (open-sourced 2010) | Original differential review; still alive as Phorge. |
| Graphite | Stripe-style startups | Layer on top of GitHub; gt CLI. |
| Sapling | Meta | Stacks are first-class commits. |
| Gerrit | Patch-set review; each commit is a changeset. | |
| Spr / git-spice / git-branchless | OSS | Bring stacked workflows to vanilla Git. |
Why it matters: review quality decays sharply past ~400 lines per PR (Smartbear, 2008 study); stacks keep each unit reviewable while preserving narrative.
2.6 · Monorepo vs polyrepo
| Dimension | Monorepo | Polyrepo |
|---|---|---|
| Atomic cross-cutting changes | Trivial | Multi-PR dance |
| Code reuse / discovery | High | Lower (search across many repos) |
| Build system requirements | Hermetic, cached (Bazel/Buck2/Pants) | Per-repo, simpler |
| Tool ecosystem | Bazel, Buck2, Nx, Turborepo, Pants 2, Moon | Native package managers |
| CI complexity | Selective builds, affected-graph | Per-repo pipelines |
| Org fit | Strong central platform team | Independent product teams |
2.7 · Code review craft
- Small PRs win. < 200 LoC changed yields the highest defect-find rate.
- Clear title, intent in the body. Conventional Commits (
feat:,fix:,chore:) enable changelog automation (Commitizen, Cocogitto, semantic-release). - "Rule of one" — one PR, one concern. Refactor and behaviour change are separate PRs.
- Self-review first. The first eyes on the diff should be the author's.
- Async by default, but escalate to a call when the comment thread crosses ~5 round-trips.
# Conventional commit examples
feat(auth): add WebAuthn enrolment endpoint
fix(billing): correct VAT rounding for EU invoices
chore(deps): bump axios 1.7.4 → 1.7.9
refactor!: drop Node 18 support # ! = BREAKING CHANGE
2.8 · Hosting platforms
| Platform | Owner | Hosted CI | Self-host? |
|---|---|---|---|
| GitHub | Microsoft | Actions | GitHub Enterprise Server |
| GitLab | GitLab Inc. | GitLab CI | Yes — CE/EE (default for many) |
| Bitbucket | Atlassian | Pipelines | Server EOL 2024; Data Center only |
| Gitea | OSS / Gitea Ltd | Gitea Actions | Yes (lightweight Go binary) |
| Gitness (formerly Drone Code) | Harness | Built-in pipelines | Yes (OSS) |
| Codeberg | Non-profit, Forgejo-based | Forgejo Actions | Public free OSS hosting |
| SourceHut | Drew DeVault | builds.sr.ht | Yes |
2.9 · Security in VCS
- Signed commits/tags — GPG (classic), SSH signing (since Git 2.34), or Sigstore Gitsign (keyless, OIDC-bound certs from Fulcio, transparency log in Rekor).
- Branch protection — required reviews, required status checks, linear history, no force-push to
main. - CODEOWNERS — auto-assign reviewers per path; combine with "code-owner approval required" to enforce stewardship.
- Push protection / secret scanning — GitHub Advanced Security, GitGuardian, Trufflehog, Gitleaks block credentials before they hit the remote.
- Tamper-evident history — protected tags,
git fsck, signed commits give cryptographic non-repudiation. - Supply chain — see Ch 16 (SLSA, in-toto attestations originate from VCS provenance).
main is forever. Reflog only saves you locally. Treat main as append-only and protect it server-side.