1
0
mirror of synced 2025-12-25 02:17:36 -05:00
Files
docs/content/github/creating-cloning-and-archiving-repositories/about-code-owners.md
Emily Gould bcfe4dab3b Make orgs and teams content a top-level doc set (#18593)
* Add new product to products.yml

* Move directory to its new location and rename it

* Update new index page

* Remove old category from GitHub product index

* Add collaboration category

* Add membership category

* Add roles category

* Add teams category

* Add team discussion category

* Add repo access category

* Add project board access category

* Add app management category

* Add org settings category

* Add improved org perms category

* Add category for OAuth app restrictions

* Add org security category

* Add SAML category

* Add SAML access category

* Add git access category

* Add redirects and update links for collaboration category

* Add redirects and update links to team discussions content

* Add redirects and update links to SAML access category

* Update links to org security category and add redirects

* Add redirects for app managers content

* Add redirects for project board category

* Add redirects and update links for the repo access category

* Add redirects for git access category

* Add redirects and update links for membership category

* Add redirects and update links for org settings category

* Fix links

* Add redirects and update links to org access category

* Add redirects and upate links to SSO category

* Add redirects to improved org perms category

* Add redirects and update links to teams category

* Add redirects and update links to oauth apps category

* Fix links

* Fix links

* Fix links
2021-04-08 09:50:13 -05:00

6.4 KiB

title, intro, redirect_from, product, versions, topics
title intro redirect_from product versions topics
About code owners You can use a CODEOWNERS file to define individuals or teams that are responsible for code in a repository.
/articles/about-codeowners/
/articles/about-code-owners
{% data reusables.gated-features.code-owners %}
free-pro-team enterprise-server github-ae
* * *
repositories

People with admin or owner permissions can set up a CODEOWNERS file in a repository.

The people you choose as code owners must have write permissions for the repository. When the code owner is a team, that team must have write permissions, even if all the individual members of the team already have write permissions directly, through organization membership, or through another team membership.

About code owners

Code owners are automatically requested for review when someone opens a pull request that modifies code that they own. Code owners are not automatically requested to review draft pull requests. For more information about draft pull requests, see "About pull requests." When you mark a draft pull request as ready for review, code owners are automatically notified. If you convert a pull request to a draft, people who are already subscribed to notifications are not automatically unsubscribed. For more information, see "Changing the stage of a pull request."

When someone with admin or owner permissions has enabled required reviews, they also can optionally require approval from a code owner before the author can merge a pull request in the repository. For more information, see "About protected branches."

{% if currentVersion == "free-pro-team@latest" or currentVersion == "github-ae@latest" or currentVersion ver_gt "enterprise-server@2.19" %}If a team has enabled code review assignments, the individual approvals won't satisfy the requirement for code owner approval in a protected branch. For more information, see "Managing code review assignment for your team."{% endif %}

{% if currentVersion == "free-pro-team@latest" or currentVersion == "github-ae@latest" or currentVersion ver_gt "enterprise-server@2.22" %} If a file has a code owner, you can see who the code owner is before you open a pull request. In the repository, you can browse to the file and hover over {% octicon "shield-lock" aria-label="The edit icon" %}.

Code owner for a file in a repository {% endif %}

CODEOWNERS file location

To use a CODEOWNERS file, create a new file called CODEOWNERS in the root, docs/, or .github/ directory of the repository, in the branch where you'd like to add the code owners.

Each CODEOWNERS file assigns the code owners for a single branch in the repository. Thus, you can assign different code owners for different branches, such as @octo-org/codeowners-team for a code base on the default branch and @octocat for a {% data variables.product.prodname_pages %} site on the gh-pages branch.

For code owners to receive review requests, the CODEOWNERS file must be on the base branch of the pull request. For example, if you assign @octocat as the code owner for .js files on the gh-pages branch of your repository, @octocat will receive review requests when a pull request with changes to .js files is opened between the head branch and gh-pages.

CODEOWNERS syntax

A CODEOWNERS file uses a pattern that follows most of the same rules used in gitignore files, with some exceptions. The pattern is followed by one or more {% data variables.product.prodname_dotcom %} usernames or team names using the standard @username or @org/team-name format. You can also refer to a user by an email address that has been added to their {% data variables.product.product_name %} account, for example user@example.com.

If any line in your CODEOWNERS file contains invalid syntax, the file will not be detected and will not be used to request reviews.

Example of a CODEOWNERS file

# This is a comment.
# Each line is a file pattern followed by one or more owners.

# These owners will be the default owners for everything in
# the repo. Unless a later match takes precedence,
# @global-owner1 and @global-owner2 will be requested for
# review when someone opens a pull request.
*       @global-owner1 @global-owner2

# Order is important; the last matching pattern takes the most
# precedence. When someone opens a pull request that only
# modifies JS files, only @js-owner and not the global
# owner(s) will be requested for a review.
*.js    @js-owner

# You can also use email addresses if you prefer. They'll be
# used to look up users just like we do for commit author
# emails.
*.go docs@example.com

# In this example, @doctocat owns any files in the build/logs
# directory at the root of the repository and any of its
# subdirectories.
/build/logs/ @doctocat

# The `docs/*` pattern will match files like
# `docs/getting-started.md` but not further nested files like
# `docs/build-app/troubleshooting.md`.
docs/*  docs@example.com

# In this example, @octocat owns any file in an apps directory
# anywhere in your repository.
apps/ @octocat

# In this example, @doctocat owns any file in the `/docs`
# directory in the root of your repository and any of its
# subdirectories.
/docs/ @doctocat

Syntax exceptions

There are some syntax rules for gitignore files that do not work in CODEOWNERS files:

  • Escaping a pattern starting with # using \ so it is treated as a pattern and not a comment
  • Using ! to negate a pattern
  • Using [ ] to define a character range

Further reading