info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments
---
# Code Owners syntax and error handling **(PREMIUM)**
This page describes the syntax and error handling used in Code Owners files,
and provides an example file.
## Code Owners syntax
### Comments
Lines beginning with `#` are ignored:
```plaintext
# This is a comment
```
### Sections
Sections are groups of entries. A section begins with a section heading in square brackets, followed by the entries.
```plaintext
[Section name]
/path/of/protected/file.rb @username
/path/of/protected/dir/ @group
```
#### Section headings
Section headings must always have a name. They can also be made optional, or
require a number of approvals. A list of default owners can be added to the section heading line.
```plaintext
# Required section
[Section name]
# Optional section
^[Section name]
# Section requiring 5 approvals
[Section name][5]
# Section with @username as default owner
[Section name] @username
# Section with @group and @subgroup as default owners and requiring 2 approvals
[Section name][2] @group@subgroup
```
#### Section names
Sections names are defined between square brackets. Section names are not case-sensitive.
[Sections with duplicate names](index.md#sections-with-duplicate-names) are combined.
```plaintext
[Section name]
```
#### Required sections
Required sections do not include `^` before the [section name](#section-names).
```plaintext
[Required section]
```
#### Optional sections
Optional sections include a `^` before the [section name](#section-names).
```plaintext
^[Optional section]
```
#### Sections requiring multiple approvals
Sections requiring multiple approvals include the number of approvals in square brackets after the [section name](#section-names).
```plaintext
[Section requiring 5 approvals][5]
```
NOTE:
Optional sections ignore the number of approvals required.
#### Sections with default owners
You can define a default owner for the entries in a section by appending the owners to the [section heading](#section-headings).
```plaintext
# Section with @username as default owner
[Section name] @username
# Section with @group and @subgroup as default owners and requiring 2 approvals
[Section name][2] @group@subgroup
```
### Code Owner entries
Each Code Owner entry includes a path followed by one or more owners.
```plaintext
README.md @username1
```
NOTE:
If an entry is duplicated in a section, [the last entry is used from each section.](index.md#define-more-specific-owners-for-more-specifically-defined-files-or-directories)
### Relative paths
If a path does not start with a `/`, the path is treated as if it starts with
a [globstar](#globstar-paths). `README.md` is treated the same way as `/**/README.md`:
```plaintext
# This will match /README.md, /internal/README.md, /app/lib/README.md
README.md @username
# This will match /internal/README.md, /docs/internal/README.md, /docs/api/internal/README.md
internal/README.md
```
### Absolute paths
If a path starts with a `/` it matches the root of the repository.
```plaintext
# Matches only the file named `README.md` in the root of the repository.
/README.md
# Matches only the file named `README.md` inside the `/docs` directory.
/docs/README.md
```
### Directory paths
If a path ends with `/`, the path matches any file in the directory.
```plaintext
# This is the same as `/docs/**/*`
/docs/
```
### Wildcard paths
Wildcards can be used to match one of more characters of a path.
```plaintext
# Any markdown files in the docs directory
/docs/*.md @username
# /docs/index file of any filetype
# For example: /docs/index.md, /docs/index.html, /docs/index.xml
/docs/index.* @username
# Any file in the docs directory with 'spec' in the name.
# For example: /docs/qa_specs.rb, /docs/spec_helpers.rb, /docs/runtime.spec
/docs/*spec* @username
# README.md files one level deep within the docs directory
# For example: /docs/api/README.md
/docs/*/README.md @username
```
### Globstar paths
Globstars (`**`) can be used to match zero or more directories and subdirectories.
```plaintext
# This will match /docs/index.md, /docs/api/index.md, /docs/api/graphql/index.md
/docs/**/index.md
```
### Entry owners
Entries must be followed by one or more owner. These can be groups, subgroups,
and users. Order of owners is not important.
```plaintext
/path/to/entry.rb @group
/path/to/entry.rb @group/subgroup
/path/to/entry.rb @user
/path/to/entry.rb @group@group/subgroup@user
```
#### Groups as entry owners
Groups and subgroups can be owners of an entry.
Each entry can be owned by [one or more owners](#entry-owners).