Read Anthropic’s case study about Graphite Reviewer

How to set up GitHub code owners for code review

Sara Verdi
Sara Verdi
Graphite software engineer


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 and integrate with Graphite Protections for enhanced merge requirements.

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.

Graphite Protections can enhance the functionality of GitHub code owners by allowing more granular control over pull request mergeability. It integrates seamlessly with GitHub’s CODEOWNERS, Branch Protection Rules, and Rulesets. Here’s how to integrate Graphite Protections:

Make sure your organization has the Graphite GitHub app installed and configured correctly.

Visit the Protections page in Graphite to configure your merge requirements. You can set up requirements such as:

  • Required CI checks
  • Minimum number of approvals
  • Specific file approvers based on file path or type

You can also configure overrides for these protections, such as allowing a merge when the designated reviewer is unavailable.

Graphite continuously evaluates pull requests against these protections. In GitHub, users will see a status check that prevents merging until the pull request meets the conditions specified in Graphite Protections.

Setting up GitHub code owners streamlines the code review process by automating the assignment of reviewers. Integrating Graphite Protections offers additional control and flexibility, ensuring that pull requests meet all necessary conditions before merging, tailored specifically to your team's needs. By leveraging both GitHub and Graphite features, teams can maintain high code quality and adhere to best practices more efficiently.

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2