my-git

CODEOWNERS

English 中文

CODEOWNERS is used to declare which individuals or teams are responsible for reviewing specific paths.

When a PR modifies specific paths, GitHub can automatically request a Review from the corresponding owner. When combined with branch protection, it can also require approval from the respective owner before merging.

Where to Place the File

GitHub supports placing the CODEOWNERS file in these locations:

.github/CODEOWNERS
CODEOWNERS
docs/CODEOWNERS

Place it at .github/CODEOWNERS, together with repository collaboration templates.

Example

# Default owner
* @team-platform

# Platform engineering
/.github/ @team-platform
/scripts/ @team-platform

# Business modules
/billing/ @team-billing
/auth/ @team-security
/docs/ @team-docs

Learning from Kubernetes OWNERS

The Kubernetes OWNERS file separates reviewers and approvers:

GitHub CODEOWNERS does not have these two semantic layers built-in, but enterprise teams can simulate them in their processes:

Common Issues

1. Owner lacks write access

GitHub requires users or teams listed as code owners to have write access to the repository; otherwise, it will not work as expected.

2. Team is not visible

If using a team as an owner, team visibility and permissions must also be configured correctly.

3. Rules are too granular

Overly granular rules can cause PRs to be blocked by too many people. Cover critical directories first and then gradually expand.

Further Reading