doc/user/project/codeowners/_index.md
{{< details >}}
{{< /details >}}
Use the Code Owners feature to define who has expertise for specific parts of your project's codebase.
[!note] Code Owners is a workflow tool, not a security or compliance control. In certain conditions, merges can proceed without Code Owner approvals. For strict security or compliance requirements, use merge request approval policies.
Define the owners of files and directories in a repository to:
Require owners to approve changes. Combine protected branches with Code Owners to require experts to approve merge requests before they merge into a protected branch. For more information, see Code Owners and protected branches.
Identify owners. Code Owner names are displayed on the files and directories they own:
Combine Code Owners with merge request approval rules (either optional or required) to build a flexible approval workflow:
For example:
| Type | Name | Scope | Comment |
|---|---|---|---|
| Approval rule | UX | All files | A user experience (UX) team member reviews the user experience of all changes made in your project. |
| Approval rule | Security | All files | A security team member reviews all changes for vulnerabilities. |
| Code Owner approval rule | Frontend: Code Style | *.css files | A frontend engineer reviews CSS file changes for adherence to project style standards. |
| Code Owner approval rule | Backend: Code Review | *.rb files | A backend engineer reviews the logic and code style of Ruby files. |
For information about who is eligible to approve merge requests as either an approver or Code Owner, see approver by membership type.
To ensure merge request changes are reviewed and approved by Code Owners, specified in the
CODEOWNERS file, the merge request's target branch must be
protected
and Code Owner approval must be enabled.
The following features are available when you enable Code Owner approvals on protected branches:
Your project contains sensitive and important information in a config/ directory. You can:
CODEOWNERS file.main.CODEOWNERS file to add a rule for multiple approvals.With this configuration, merge requests that change files in the config/directory and target the main branch
require approval from the designated Code Owners before merging.
Users who are Allowed to push and merge can choose to create a merge request for their changes, or push the changes directly to a branch. If the user skips the merge request process, the protected branch features and Code Owner approvals built into merge requests are also skipped.
This permission is often granted to accounts associated with automation (internal users) and release tooling.
All changes from users without the Allowed to push permission must be routed through a merge request.
To view the Code Owners of a file or directory:
GitLab shows the Code Owners at the top of the page.
Prerequisites:
CODEOWNERS file in your preferred location.CODEOWNERS syntax.
Some suggestions:
CODEOWNERS fileThe CODEOWNERS file defines who is responsible for code in a GitLab project.
Its purpose is to:
This file determines who should review and approve changes and ensures the right experts are involved in code changes.
Each repository uses a single CODEOWNERS file. GitLab checks these locations
in your repository in this order. The first CODEOWNERS file found is used, and
all others are ignored:
./CODEOWNERS.docs directory: ./docs/CODEOWNERS..gitlab directory: ./.gitlab/CODEOWNERS.For more information, see CODEOWNERS syntax and advanced CODEOWNERS configuration.