Sub topic 3
Naming owners: users, teams, and emails
This chapter assumes you know basic Git and GitHub use, can read .gitignore-style patterns, and understand repository roles and organization teams. It covers the owner side of a CODEOWNERS rule: the part after the path pattern.
The three owner forms
Each line in a CODEOWNERS file has a path pattern followed by one or more owners, separated by whitespace. GitHub accepts three kinds of owner identifier.
| Form | Example | Notes |
|---|---|---|
| Username | `@octocat` | A GitHub user. The `@` is required. |
| Team | `@example-org/frontend` | Written as `@org/team-slug`. Use the team's slug, not its display name. |
| Email address | `[email protected]` | Must match an email address on a verified GitHub account. |
You can mix forms on one line, as in this example from the plan:
# .github/CODEOWNERS
/docs/ @example-org/docs-team [email protected]
/scripts/build/ @octocatEvery owner listed on a line is a code owner for matching files. Listing several owners does not mean all of them must approve. Approval rules come later, in the chapter on how code owner approval is satisfied.
What makes an owner valid
An owner only works if GitHub can resolve it and it has enough access. Check these points:
- Users need write access to the repository. A user with only read access is ignored for review requests.
- Teams must be visible and must have write access to the repository. A team that exists in the organization but was never granted access to this repository cannot be an owner.
- Teams need an organization. The
@org/teamform works only for repositories owned by that organization. - Emails must belong to a user account. If nobody has verified that address, the rule has no effect.
When an owner is invalid, GitHub does not fail the whole file. It marks that line as an error and skips the bad owner. The error appears in the file view, which a later chapter on validation covers.
Choosing between users and teams
Prefer teams for anything that will outlive one person's assignment. When someone changes roles, you update team membership instead of editing the file and opening a pull request. Teams also spread review requests across members when the team has review assignment enabled.
Use an individual username when one person truly owns a path, such as a single build script. Use an email address when you know the person but not their username, or when your tooling records emails. Emails are the most fragile option, because the match depends on which addresses a person has verified.
How owner names are read
Exercise
A CODEOWNERS line reads /api/ @example-org/Backend Team. Reviews are never requested for files in /api/. Name two problems with this line and how to fix them.
Show answer
The team is written with its display name and a space. Owners are separated by whitespace, so GitHub reads @example-org/Backend and Team as separate entries, and neither resolves. Use the team slug, for example @example-org/backend-team. Also confirm the team has write access to the repository, because a team without it is ignored even when the name is correct.