Skip to content

Say hello to the new PR page.

Read more

How to set up GitHub code owners for code review

Sara Verdi
Sara Verdi
Graphite software engineer
Try Graphite


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


Setting up GitHub code owners is an effective way to automatically assign code review responsibilities based on specific file paths or directories within a repository. This guide provides a step-by-step process on how to implement GitHub code owners.

GitHub code owners are defined in a special file in the repository called CODEOWNERS, located in the repository’s root, docs/, or .github/ directory. This file specifies which users or teams are responsible for the code in specific directories or files. When changes are made to these areas, the specified code owners are automatically requested for review.

Here’s how to set up GitHub code owners for your project:

Start by creating a CODEOWNERS file in one of the three locations mentioned above:

  • Repository’s root
  • docs/ directory
  • .github/ directory

In the CODEOWNERS file, define code owners by specifying file patterns followed by the GitHub usernames or team names. Here’s an example format:

Terminal
# Syntax: pattern @username or @teamname
# Example to set code owners:
* @default-team
# Frontend team owns all html and css files
*.html @frontend-team
*.css @frontend-team
# Backend team owns all scripts
/scripts/ @backend-team

Commit the CODEOWNERS file to your repository and push it to GitHub. Once pushed, GitHub will use this file to automatically assign reviewers for pull requests that modify the specified files.

When a pull request is opened, GitHub automatically requests reviews from the code owners if the changes affect any files or paths listed in the CODEOWNERS file. This automates the assignment of code reviews based on the file paths impacted by the pull request.

Setting up GitHub code owners streamlines the code review process by automating the assignment of reviewers.

Git inspired
Graphite's CLI and VS Code extension make working with Git effortless.
Learn more

Built for the world's fastest engineering teams, now available for everyone