Using CODEOWNERS for Enforced Reviews
Introduction
Section titled โIntroductionโA CODEOWNERS
file assigns responsibility for parts of the repository so GitLab can request approvals from the right people.
Create a CODEOWNERS File
Section titled โCreate a CODEOWNERS Fileโ- Add a
CODEOWNERS
file in the repository root,docs/
, or.gitlab/
directory. - List file patterns followed by usernames or groups, for example:
docs/* @technical-writerssrc/frontend/ @frontend-team
- Commit and push the file to the default branch.
Enforce Approvals
Section titled โEnforce Approvalsโ- Go to Settings > Repository > Protected branches and enable Require approval from code owners.
- Merge requests that touch owned files will require approval from listed owners before merging.
Best Practices
Section titled โBest Practicesโ- Keep patterns as specific as possible to avoid unexpected approvals.
- Use groups rather than individual usernames for easier maintenance.
- Review ownership regularly as teams change.