Skip to main content
Configure a CODEOWNERS file to require specific reviewers for changed files and automatically request them on pull requests. This guide explains where to place the file, how to format entries, common validation errors, and how to resolve team visibility and permission issues so GitHub will auto-request reviewers.

Context: repository behavior and why CODEOWNERS is needed

In this lesson we use a GHAS schedules demo repository. When you create a branch and open a pull request, you may notice no automatic reviewers are requested because:
  • This is a public repository, so enterprise-level rule sets do not apply.
  • There are no repository-level rule sets configured that require reviewers.
To enforce reviewers when certain paths or file types change, add a .github/CODEOWNERS file to the repository.

Example: existing PR template (kept for context)

Where to place CODEOWNERS

Best practice is to create the CODEOWNERS file under the repository’s .github directory:
  • Path: .github/CODEOWNERS
  • Commit it to the default branch (commonly main) so GitHub applies it to new PRs.
Place .github/CODEOWNERS on the repository default branch (e.g., main) so new pull requests trigger the configured owners automatically. If you don’t have direct write access to main, add the file via a pull request.

CODEOWNERS file format and examples

Use @org/team-slug to reference teams and @username for individuals. Patterns follow GitHub’s CODEOWNERS glob-like syntax. Simple example: require @game-devstudio/pc-devs review for any .js file:
Examples of useful patterns: For full pattern reference, see GitHub’s documentation: About code owners.

Common validation errors and how to resolve them

When committing a CODEOWNERS file, GitHub may show a validation error. Typical causes and resolutions are:
If a referenced team lacks write access or is private/invisible to the repository, GitHub will treat the CODEOWNERS entry as invalid. Ensure the referenced team exists, is visible (if required), and has at least Write permission on the repository.
To check and adjust team visibility and repository access, go to your organization settings:
  • Organization > Teams (select team) — confirm slug and visibility.
  • Repository > Settings > Collaborators and teams — grant the team Write access.
Screenshot of a GitHub organization team page (PC-Devs) in dark mode showing "Repositories with direct access" and a single repo listed: "game-devstudio/app-backend" with Role: Write and an "Add repository" button. The top bar shows navigation tabs and a prompt about trying GitHub Enterprise.
After granting the team write access and ensuring the team is visible, refresh the CODEOWNERS page in GitHub. The validation error should disappear and the CODEOWNERS file will be accepted:

Commit and workflow considerations

  • Commit the CODEOWNERS file to the default branch so it applies to new PRs.
  • If you cannot commit directly to the default branch, open a pull request adding the .github/CODEOWNERS file; once merged, it will take effect.
  • GitHub will automatically request the specified owners when matching files are changed in future PRs.

Quick checklist before committing CODEOWNERS

  • File placed at .github/CODEOWNERS.
  • Entries use correct @org/team-slug or @username.
  • Teams referenced exist and slugs are correct.
  • Teams have at least Write access to the repository.
  • File committed to the repository default branch.

References and further reading

That’s it — with .github/CODEOWNERS configured and the referenced team visible with write access, changes to *.js files will trigger review requests for @game-devstudio/pc-devs.

Watch Video