A CODEOWNERS file in GitHub is a plain text file that maps files and folders to the people or teams responsible for them. When a pull request changes a matching file, GitHub automatically requests a review from the listed owners. With branch protection turned on, their approval can be made mandatory before the merge. The file keeps review duties clear in a busy repository.
The feature is simple to set up, and the main skill is writing the patterns correctly. This guide covers where the file goes, the syntax, the rules for which entry wins, and how to enforce the reviews.
In a large project nobody can review every change. A CODEOWNERS file records who knows each part of the code, for example the payments team for /payments/ and a security group for the authentication code. GitHub reads it on every pull request and does two things:
Owners must have write access to the repository, otherwise the entry is ignored.
GitHub looks for the file in one of three places in the branch the pull request targets, using the first one it finds:
.github/CODEOWNERSCODEOWNERS in the repository rootdocs/CODEOWNERSMost projects use .github/CODEOWNERS. The file is read from the base branch, so changing it inside a pull request does not affect that same pull request.
Each line has a path pattern followed by one or more owners. A # starts a comment:
Owners can be written as:
| Form | Example |
|---|---|
| A user | @alice |
| A team in an organisation | @octo-org/payments-team |
| An email address tied to a GitHub account | [email protected] |
Patterns follow most of the .gitignore rules. A leading / anchors the path to the repository root, a trailing / matches a directory, and * and ** work as wildcards. Negation with ! and character ranges in [ ] are not supported.
The last matching pattern in the file takes precedence. For that reason, put the general rules first and the specific ones after them. In the example above, a change to /services/payments/charge.go matches both * and /services/payments/, and the payments rule wins because it comes later.
If the owners of the winning line are empty, the file has no owner at all, which is a way to opt a path out of the default owners:
A line with a pattern and no owners means nobody is required to review those files.
By itself, the file only requests reviews. To block merging until an owner approves, enable the protection setting:
main.From then on, a pull request that touches /services/auth/ needs an approval from someone in @octo-org/security-team. If the author is the only owner, they cannot approve their own pull request, so keep at least two owners per area.
GitHub shows an error icon next to a broken line in the file view, for example when a team does not exist or has no write access. Open the CODEOWNERS file on GitHub and check for the warning banner before you rely on it. Common mistakes are:
! negation, which silently does nothing.For enforcement, yes. The file alone only requests reviewers. Branch protection with Require review from Code Owners makes the approval mandatory.
Yes. List them on one line separated by spaces. Any one of them can satisfy the Code Owner requirement.
The file is read from the target repository, so pull requests from forks also request the owners of the files they change.
You can, and it still helps by auto-assigning you. The mandatory approval part needs another person, since authors cannot approve their own work.
A CODEOWNERS file in .github/ links paths to people or teams, requests their review automatically, and, together with branch protection, can require their approval. Order your patterns from general to specific, check the file for errors, and keep more than one owner per area.