Skip to main content
RunBook Academy

Git, CI/CD & GitOpsXXXI · CODEOWNERS and Ownership ControlsOwnership

What CODEOWNERS is — a file in the repo that maps paths to owners

Advanced⏱ ~19 mingit

What you'll learn

  • Locate the CODEOWNERS file in a repository and explain where each forge expects it
  • Explain the difference between CODEOWNERS as a reviewer suggestion and as a merge gate
  • Read a CODEOWNERS entry and predict which path it covers
  • Identify why CODEOWNERS alone is not a control until wired to branch protection

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.

CODEOWNERS is a single file in the repository whose only job is to answer “who is responsible for this path?”. Every line pairs a path pattern with one or more owners. The file is plain text, lives under version control, and is read by the forge when a pull request touches one of the listed paths.

Where the file lives

Each forge looks in a slightly different place. GitHub searches .github/CODEOWNERS, CODEOWNERS, then docs/CODEOWNERS (first match wins). GitLab searches .gitlab/CODEOWNERS, CODEOWNERS, or a configured path. Bitbucket expects CODEOWNERS at the repo root.

ls .github/CODEOWNERS
cat .github/CODEOWNERS
git ls-files | grep CODEOWNERS

The third command is authoritative: it shows the tracked copy, not whatever happens to exist in a clone. An untracked CODEOWNERS file is invisible to the forge.

What the file contains

Each non-comment line pairs a pattern with one or more owners. A minimal example for an infrastructure repository:

*                  @platform/platform-infra
/terraform/        @platform/platform-infra
/terraform/prod/   @platform/platform-infra @security-team
/prod/secrets.yaml @security-team

The file is data. It does not, by itself, prevent anything. A CODEOWNERS file with no branch protection attached is a file that documents ownership and nothing more.

flowchart LR
    A[Pull request opened] --> B[Forge reads CODEOWNERS]
    B --> C{Path matches a rule?}
    C -->|yes| D[Assign those owners as reviewers]
    C -->|no| E[Fall through to default reviewers]
    D --> F{Branch protection requires code-owner review?}
    E --> F
    F -->|yes| G[Merge blocked until owners approve]
    F -->|no| H[Owners assigned but not required]

How forges interpret the file

All three major forges use CODEOWNERS to assign reviewers, but they differ on whether the assignment is a suggestion or a gate. GitHub consults the file for suggested reviewers by default; the branch protection setting “Require review from Code Owners” promotes the suggestion to a requirement. GitLab uses the file as the source for a codeowners approval rule, which must be promoted in protected-branch settings. Bitbucket routes to owners, and a branch permission decides whether owner approval is required.

In every case the file is a list of paths and owners; what the forge does with the list is configured elsewhere.

Production discipline

A new CODEOWNERS file is a control with three dependencies. The file is tracked. Branch protection requires reviews from Code Owners on every branch that matters. The teams referenced in the file exist, have members, and have members with merge rights. If any of those three is missing, CODEOWNERS is documentation, not a control.

Cross-course references

  • Linux for Production Sysadmins - Part XII (RepoSecurity) covers repository trust at the system level; CODEOWNERS is the team-level analogue.
  • Ansible for Production Sysadmins - Part XXXVIII (RBACIntegration) covers role-based access patterns that map onto CODEOWNERS teams.

Quiz

Knowledge check · 4 questions

  1. Q1. A team writes a CODEOWNERS file and pushes it to the default branch. Two days later a junior engineer merges a PR that touches a CODEOWNERS-owned path with no owner review. What went wrong?

  2. Q2. A CODEOWNERS file in the repository is consulted by the forge on every pull request even when no branch-protection rule references it.

  3. Q3. Name the three things that must be true for a CODEOWNERS file to function as a control rather than documentation.

  4. Q4. Diagnose why CODEOWNERS is being treated as documentation rather than a control.

    A monorepo serves five product teams. CODEOWNERS assigns each service directory to a product team. The default branch has branch protection requiring two approvals before merge. Engineers report that CODEOWNERS owners are auto-assigned but their approvals are not required - any two reviewers count. A junior engineer merged a change to the payments service with approval only from the frontend team.

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