LOOP · The DevOps Codex
Ch 02 · Version Control & Branching
Chapter 02 · Source of Truth

Version Control & Branching — the substrate of every pipeline

Every artefact, every deployment, every rollback in DevOps starts from a commit hash. The branching model you pick will silently dictate your batch size, your review latency, and your DORA score for years. This chapter maps the version-control landscape in 2026, dissects Git's internals, and compares the strategies that scale.

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.

ToolModelWhere it shines (2026)Share*
Git (Linus Torvalds, 2005)Distributed, content-addressedUniversal default; vast ecosystem.~94%
Mercurial (hg)Distributed, simpler UX than GitMozilla & Meta (largely on Sapling now).~1%
Subversion (SVN)CentralisedLegacy enterprise, large binaries.~2%
Perforce / Helix CoreCentralised, file-lockingAAA game studios, EDA, huge binary assets.~1%
Fossil (D. Richard Hipp)Distributed + bug tracker + wikiSQLite project; self-contained single binary.<1%
Sapling (Meta, 2022)Mercurial-derived, Git-compatibleMassive monorepos, friendlier UX.<1%
Jujutsu / jj (Google, 2023)Git-compatible, snapshot-based, Mercurial-influencedPower 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.

ObjectWhat it stores
blobFile contents — just bytes, no name.
treeA directory: a list of (mode, name, blob/tree hash) entries.
commitA 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 that git commit would 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

StrategyOriginBatch sizeBest for
Trunk-Based DevelopmentPaul Hammant; long-standing Google/FB practiceTiny (hours)CI/CD orgs aiming for Elite DORA.
GitHub FlowGitHub blog (Scott Chacon, 2011)Small (days)SaaS, single-environment products.
GitLab FlowGitLab (2014)Small + environment branchesProducts with staging/prod gates.
Git-FlowVincent Driessen, 2010Large (weeks)Versioned/boxed software with multiple supported releases.
Release TrainSAFe, SpotifyTime-boxedBig orgs that must align dozens of teams to a cadence.
Stacked PRsPhabricator, Graphite, SaplingTiny + dependentLong, decomposable refactors.
Git-Flow caveat. Driessen himself added a note in 2020 stating Git-Flow is overkill for continuously delivered web software — keep it only when you genuinely ship versioned releases.

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.
Accelerate (2018) finding: TBD is one of only a handful of practices statistically correlated with elite software delivery performance.

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.

ToolBacked byNotes
Phabricator / PhorgeFacebook (open-sourced 2010)Original differential review; still alive as Phorge.
GraphiteStripe-style startupsLayer on top of GitHub; gt CLI.
SaplingMetaStacks are first-class commits.
GerritGooglePatch-set review; each commit is a changeset.
Spr / git-spice / git-branchlessOSSBring 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

DimensionMonorepoPolyrepo
Atomic cross-cutting changesTrivialMulti-PR dance
Code reuse / discoveryHighLower (search across many repos)
Build system requirementsHermetic, cached (Bazel/Buck2/Pants)Per-repo, simpler
Tool ecosystemBazel, Buck2, Nx, Turborepo, Pants 2, MoonNative package managers
CI complexitySelective builds, affected-graphPer-repo pipelines
Org fitStrong central platform teamIndependent product teams
Monorepo web api infra shared/libs · single BUILD graph Polyrepo repo-web repo-api repo-infra artefact registry as glue

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

PlatformOwnerHosted CISelf-host?
GitHubMicrosoftActionsGitHub Enterprise Server
GitLabGitLab Inc.GitLab CIYes — CE/EE (default for many)
BitbucketAtlassianPipelinesServer EOL 2024; Data Center only
GiteaOSS / Gitea LtdGitea ActionsYes (lightweight Go binary)
Gitness (formerly Drone Code)HarnessBuilt-in pipelinesYes (OSS)
CodebergNon-profit, Forgejo-basedForgejo ActionsPublic free OSS hosting
SourceHutDrew DeVaultbuilds.sr.htYes

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).
Force-push to main is forever. Reflog only saves you locally. Treat main as append-only and protect it server-side.

2.10 · Self-check

Q1 · Which Git object stores the directory layout (filenames, modes, child hashes)?
blob
tree
commit
tag
Q2 · Trunk-Based Development relies on which technique to merge unfinished features safely?
Long-lived release branches
Manual change advisory boards
Feature flags
Git-Flow hotfix branches