Learn and Use the GitHub CODEOWNERS file

A laptop with GitHub stickers

A CODEOWNERS file is a text file used to define code owners for specific files or directories in a GitHub repository.

It's a great way to ensure changes to the codebase are reviewed by the appropriate team members.

The people/teams listed in your CODEOWNERS auto-magically get added to pull request reviews.

Creating a CODEOWNERS file

In the root of your project, docs/ directory or the .github/ directory, create a new file called CODEOWNERS.

Syntax and structure

The syntax for the file is simple - a simple pattern-matching syntax to assign code owners for specific files or directories.


# This is a comment - Helpful for leaving notes.

# Default code owners
# Will require approval from @NiallJoeMaher or @anotheruser
* @NiallJoeMaher @anotheruser

# Specific code owners for a subdirectory
# Will require approval from @NiallJoeMaher
/subdir/ @NiallJoeMaher

# Specific code owners for a file type
# Will require approval from @anotheruser
*.js @anotheruser

# Example with a specific file
# Will require approval from the team @codu-code/maintainers
/docs/README.md @codu-code/maintainers
  • The asterisk (*) represents a global pattern that matches all files and directories.
  • The directory or file pattern is followed by one or more GitHub usernames or team names (prefixed with '@').

What next?

When you open a pull request, depending on the conditions set in your CODEOWNERS file, the appropriate people will be added as reviewers to your PR. 🎉

Best practices

  • Maintain an up-to-date CODEOWNERS file: Regularly verify the list of code owners to ensure accuracy and make updates when team structures change.
  • Implement a modular strategy: For repositories containing numerous subdirectories with distinct responsibilities, establish individual rules within the CODEOWNERS file to enhance the organization of code ownership.
  • Promote teamwork: Don't leave it all to your CODEOWNERS - Cultivate a collaborative atmosphere by motivating team members to evaluate and offer feedback on their colleagues' code, regardless of whether they are officially designated as code owners.

Follow me on Twitter or connect on LinkedIn.

🚨 Want to make friends and learn from peers? You can join our free web developer community here. 🎉

GithubOpen SourceWeb DevelopmentOss
Avatar for Niall Maher

Written by Niall Maher

Founder of Codú - The web developer community! I've worked in nearly every corner of technology businesses; Lead Developer, Software Architect, Product Manager, CTO and now happily a Founder.


Fetching comments

Hey! 👋

Got something to say?

or to leave a comment.