CODEOWNERS File Generator
Create a CODEOWNERS file row by row: a file-path pattern on the left, one or more owners on the right. The generator validates that each owner is a @username, @org/team, or email, warns about common mistakes, and emits the file in the order these systems expect — general rules first, specific rules last, since the last match wins. Works for GitHub, GitLab, and Bitbucket.
How to use the CODEOWNERS File Generator
Each rule pairs a path pattern with the people or teams responsible for matching files. Put broad rules — such as a catch-all * — near the top and narrow rules below them; the file is read top to bottom and the last matching line decides ownership, so the most specific pattern must come last. List multiple owners separated by spaces, each one a @user, an @org/team, or an email address.
The generated file goes at .github/CODEOWNERS, CODEOWNERS in the repo root, or docs/CODEOWNERS on GitHub; GitLab and Bitbucket look in similar locations. Once committed, owners are requested for review automatically when a pull or merge request touches files they own. Warnings below the output flag owners missing an @ and patterns that look malformed.
How CODEOWNERS works
A CODEOWNERS file declares who owns which parts of a repository. Each non-comment line is a path pattern followed by one or more owners. When someone opens a pull or merge request, the platform finds the files it changes, matches them against the patterns, and automatically requests review from the owners — and, if branch protection requires owner approval, blocks the merge until they sign off.
The pattern syntax follows gitignore rules: * matches anything, / anchors to the repository root, a trailing / matches a directory, and ** spans directories. Owners are GitHub or GitLab usernames and teams prefixed with @ (for example @octocat or @acme/backend), or plain email addresses for users whose commit email the platform recognises. A line with a pattern and no owners explicitly removes ownership inherited from a broader rule above it.
The single rule that trips people up is precedence: the last matching pattern wins, not the most specific one. So a general line like * @acme/maintainers belongs at the top, and a targeted line like /infra/ @acme/platform belongs below it, so that changes under infra/ route to the platform team rather than the catch-all. Ordering the file from broad to narrow is what makes ownership behave the way you expect.
Common use cases
- Automatic review routing. Request the right team's review the moment a PR touches their code.
- Enforcing sign-off. Pair with branch protection so owners must approve changes to critical paths.
- Onboarding a monorepo. Map each top-level directory to the team that maintains it.
- Documenting ownership. Give a clear, version-controlled record of who is responsible for what.