CODEOWNERS and templates

Intermediate · 25 min

Route reviews to the right people with a CODEOWNERS file, and give contributors issue forms and a pull request template so reports arrive with what you need.

Before thisPull requestsCode review on GitHubIssues and projectsBranch protection and rulesets

Swiftful Thinking · 25 min

CODEOWNERS and templates

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Swiftful ThinkingReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • A CODEOWNERS file maps file patterns to the people or teams responsible for them, and GitHub requests their review automatically on pull requests that touch those files.
  • In CODEOWNERS the last matching pattern wins, so put general rules first and specific ones after.
  • Owners only block merging if a branch protection rule or ruleset requires review from code owners, and any one owner's approval satisfies it.
  • Issue forms are YAML files in .github/ISSUE_TEMPLATE that turn a free-text issue into fields, some of them required.
  • A pull request template, usually .github/pull_request_template.md, pre-fills the description with a checklist.

Two small files that save a lot of time

A project grows to the point where no one person knows every part. The person who wrote the build scripts should review changes to them, and the person who owns the docs should see doc changes. Left to chance, a pull request is reviewed by whoever happens to be online.

Separately, issues arrive as “it’s broken”. You want the version, the steps and the expected result, and you do not want to ask for them every time.

Both are solved by plain files in the repository.

CODEOWNERS

A CODEOWNERS file maps patterns to the people or teams responsible. When a pull request changes a matching file, GitHub requests a review from those owners.

It can live in .github/, the repository root, or docs/. If several exist, GitHub uses the first it finds in that order. A small example for the notes project:

# Later lines override earlier ones.
*                       @ada
/src/                   @ada @grace
docs/*                  @notes-org/docs
*.md                    @notes-org/docs
/.github/workflows/     @ada

Read it top to bottom. Everything belongs to @ada by default, which is the catch-all that makes sure no file is unowned. src/ adds Grace. The docs and Markdown go to a team, written @org/team. The workflows folder goes back to Ada alone.

The rules that matter

  • The last matching pattern wins. The docs say so directly: “Order is important; the last matching pattern takes the most precedence.” That is why the catch-all * is first. Put it last and it would override everything above it.
  • It looks like .gitignore but is not the same. The docs list three things that do not work: escaping a leading # with a backslash, negating a pattern with !, and character ranges in [ ].
  • docs/* does not match nested files. It covers files directly in docs/ but not in docs/guide/. To cover the whole tree, write docs/ or /docs/.
  • A pattern with no owner clears ownership. A line such as /apps/github with nothing after it leaves that path unowned.
  • Several owners belong on one line. The docs warn that if owners are not on the same line, only the last mentioned owner is matched.
  • The file must be under 3 MB. A larger one is not loaded at all.
  • One owner is enough. Approval from any one listed owner satisfies a code-owner requirement, not approval from all of them.

I tested what I could. The last-match rule works the same way in .gitignore, so I put the patterns above (without the catch-all) into a .gitignore in a scratch repository and asked git check-ignore -v --no-index which line matched each path. src/util/fmt.mjs matched /src/. docs/index.md matched *.md, a later line than docs/*, so the later one won. README.md matched *.md, and package.json matched nothing, which is why a catch-all line is useful. .github/workflows/ci.yml matched the workflows line.

The stand-in also disagreed with GitHub on one case. It reported docs/guide/start.md as matching docs/*, because .gitignore treats a matching directory as covering everything beneath it. GitHub’s docs say CODEOWNERS does not. So a .gitignore check is a fair test of ordering but a poor test of patterns, and I could not run the real thing. GitHub shows errors in a CODEOWNERS file on the file’s own page in the UI, which is the checker to use.

Making it binding

By itself CODEOWNERS only requests a review. To make it required, turn on Require review from Code Owners in a branch protection rule, or the equivalent code-owners option in a ruleset’s pull request rule, as described in branch protection and rulesets. I read that in GitHub’s docs on 2026-11-23 and could not test it, since I have no account for it.

A strong first use: own .github/workflows/ so that nobody quietly weakens the checks. GitHub’s hardening guide recommends exactly this.

Issue forms

An issue form is a YAML file in .github/ISSUE_TEMPLATE/ that replaces the blank issue box with fields. This one asks for what a bug report needs:

name: Bug report
description: Something in the notes CLI does not work as expected.
title: "[Bug]: "
labels: ["bug"]
body:
  - type: markdown
    attributes:
      value: Thanks for the report. Please fill in what you can.
  - type: input
    id: version
    attributes:
      label: notes-cli version
      placeholder: "0.1.0"
    validations:
      required: true
  - type: textarea
    id: what-happened
    attributes:
      label: What happened, and what did you expect?
    validations:
      required: true
  - type: dropdown
    id: node
    attributes:
      label: Node.js version
      options:
        - "22"
        - "24"
        - "26"
    validations:
      required: false

Top-level, name, description and body are required, and title, labels and assignees are optional. Body elements are markdown (display only), input, textarea, dropdown, checkboxes, and a file upload. I loaded the YAML above with a YAML parser, so the syntax is valid, but I could not see how GitHub renders it. GitHub’s documentation shows a similar example, and the field names follow it.

A second file, .github/ISSUE_TEMPLATE/config.yml, tunes the chooser:

blank_issues_enabled: false
contact_links:
  - name: Questions and ideas
    url: https://github.com/ada/notes-cli/discussions
    about: Ask here before opening an issue.

With blank_issues_enabled: false, only people with Write, Maintain or Admin access still see a blank-issue option, labelled “Maintainers only”. The configuration takes effect once the file is merged into the default branch. Not every repository has Discussions turned on, so point that link at somewhere real.

A pull request template

A pull request template pre-fills the description. Save it as .github/pull_request_template.md. The root and docs/ also work. Several templates go in a PULL_REQUEST_TEMPLATE/ folder and are chosen with a template query parameter.

## What and why

<!-- One or two sentences. Link the issue: Closes #123 -->

## How I checked it

- [ ] `npm test` passes
- [ ] Added or updated a test

Keep it short. A template with fifteen checkboxes gets ticked without being read.

What the video covers

Swiftful Thinking’s “How to Add Branch Rules, CodeOwners, Pull Request Templates | Git & Source Control #11” is about 25 minutes and was published around 2024. The description says it covers adding branch rules, CodeOwners and pull request templates. It is the only video I found that covers CODEOWNERS and templates together. I could not read a transcript or chapters, so I do not know how it splits its time. It is part of a series by an iOS developer, so the examples may be Xcode-flavoured. It also overlaps the previous lesson on branch rules, and it predates the rulesets interface. English is judged from the title and description. Issue forms, config.yml and the CODEOWNERS pattern rules above come from the docs, not from the video.

Where this fits

You now have the collaboration loop: authenticate, publish, branch, review, merge, protect. Everything so far was clicking in a browser. The GitHub CLI does the same from the terminal.

Check yourself

  1. 01Two lines in CODEOWNERS both match src/cli.mjs. Which owner is requested?

    The one on the later line. The last matching pattern takes precedence, which is why broad patterns go first and exceptions after.

  2. 02CODEOWNERS lists you for src/, but a PR touching src/ merged without your review. Why?

    Listing owners only requests their review. To make it mandatory, a branch protection rule or ruleset must require review from code owners.

  3. 03Where must an issue form file live, and in what format?

    In the .github/ISSUE_TEMPLATE folder, as a YAML file with a name, a description and a body of input elements.

  4. 04Why protect .github/workflows with CODEOWNERS?

    Whoever can change a workflow can change what your checks and deployments do. Requiring a trusted owner's review on that folder stops a quiet edit from weakening them.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark