Code Owners

A CODEOWNERS file auto-requests the right reviewers based on which files change.

The CODEOWNERS file maps file paths to the people or teams responsible for them. When a PR touches those paths, GitHub automatically requests a review from the owners.

Where it lives

Put it at .github/CODEOWNERS, in the repo root, or in docs/. Each line is a path pattern followed by one or more owners.

Combine it with branch protection's Require review from Code Owners to guarantee the right people sign off.

Example

Example · yaml
# .github/CODEOWNERS
# Default owners for everything
*                 @org/core-team

# Front-end files
/src/ui/          @org/frontend @alice

# CI and workflows
/.github/         @org/devops

# A single important file
package.json      @bob

When to use it

  • The payments team is set as a CODEOWNER for src/billing/ so any PR touching payment code automatically requests their review.
  • A security engineer is listed as the owner of .github/workflows/ so no CI/CD change can be approved without their sign-off.
  • A frontend team owns src/components/ and is auto-assigned on PRs that touch the UI, ensuring domain experts always review component changes.

More examples

Basic CODEOWNERS file

Defines three rules: a catch-all default, a directory-scoped rule for billing code, and another for GitHub Actions workflows.

Example · bash
cat .github/CODEOWNERS
# Default owner for all files
* @org/core-team

# Payments module requires billing team review
src/billing/ @org/billing-team

# CI workflows require DevOps review
.github/workflows/ @org/devops-team

Assign individual file owners

Shows how to assign individual users to specific files and a team to an entire directory using glob patterns.

Example · bash
cat .github/CODEOWNERS
# Security-sensitive files
src/auth/jwt.py    @alice
src/crypto/keys.py @alice @bob

# Config file any SRE can review
infra/terraform/**  @org/sre-team

Verify who owns a path

Fetches any CODEOWNERS syntax errors via the API, and git check-attr can verify which attribute patterns match a path locally.

Example · bash
# GitHub CLI: check ownership for a file path
gh api repos/{owner}/{repo}/codeowners/errors

# Or use a local script to parse the rules
git check-attr -a src/billing/invoice.py

Discussion

  • Be the first to comment on this lesson.