---
title: "Which CODEOWNERS line owns a file when several match? | Proofline"
description: "GitHub applies only the last CODEOWNERS line that matches a file, so a broad pattern below a narrow one takes the path from its team."
url: https://proofline.sh/learn/codeowners-last-matching-pattern-wins/
---

[Learning center](/learn/)

# Which CODEOWNERS line owns a file when several match?

GitHub applies only the last CODEOWNERS line that matches a file, so a broad pattern below a narrow one takes the path from its team. Order the file from broad to narrow, put deliberate overrides at the end, and check one file in each team's area before you make code owner review required.

Code review The Proofline team November 23, 2026 4 min read

## How GitHub picks the owner

GitHub's example CODEOWNERS file states the rule in a comment: "Order is important; the last matching pattern takes the most precedence." Its example continues with `* @global-owner1 @global-owner2` followed by `*.js @js-owner`, and explains that a pull request that only changes JavaScript files requests `@js-owner` "and not the global owner(s)." [About code owners: example file](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners#example-of-a-codeowners-file)

The owners of the matching lines are never combined. The same page says that to give one pattern two or more owners, "all the code owners must be on the same line. If the code owners are not on the same line, the pattern matches only the last mentioned code owner." [CODEOWNERS syntax](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners#codeowners-syntax) A narrow line written early in the file therefore does nothing for any file that a later, broader line also matches. Nothing warns you: the file has no syntax error, and the later team is requested as if it were the intended owner.

## Node.js: one rule, two outcomes

The Node.js CODEOWNERS file shows both the intended and the accidental use of the rule. [nodejs/node .github/CODEOWNERS](https://github.com/nodejs/node/blob/main/.github/CODEOWNERS), read on 2026-11-23. Its header says the file "does not define any requirements for landing PRs" and exists for "courtesy pings to the relevant team(s)," so in Node the consequence is who gets notified, not who must approve.

The intended use sits in the Actions section:

```
/.github/workflows/* @nodejs/actions
/.github/workflows/create-release-proposal.yml @nodejs/releasers
```

The second line comes later, so a change to the release proposal workflow requests `@nodejs/releasers` and not `@nodejs/actions`.

The same rule applies to the dependency directories, whether or not that was the plan. Early sections assign individual dependencies to their teams:

```
/deps/cares @nodejs/net
/deps/llhttp/* @nodejs/http @nodejs/net
/deps/v8/* @nodejs/v8-update
```

Much further down, under "Dependency Update Tools," comes:

```
/deps @nodejs/security-wg
```

`/deps` covers the whole directory, in the same way that GitHub's documented example uses `/apps/github` to cover a subdirectory. Read by the documented rule, every file those earlier lines match, such as `deps/cares/cares.gyp` and `deps/v8/DEPS`, also matches `/deps`, which comes last. Those files request `@nodejs/security-wg` alone. The `*.gyp @nodejs/gyp` line, also earlier, loses `deps/cares/cares.gyp` the same way. Dependency lines placed after `/deps`, such as `/deps/sqlite/ @nodejs/sqlite` and `/deps/ada @nodejs/url`, keep their teams.

The file does not say whether the net, HTTP and V8 teams were meant to stop receiving those pings. That is the point: in the text of the file, an intended override and an accidental one look identical. In a repository that required code owner review, the same ordering would let one security team approval satisfy the requirement for the V8 directory without the V8 team seeing the change.

## Check ownership before it matters

GitHub shows the result for any single file. Browse to the file and hover over the shield icon in its header; the tooltip reads "Owned by USER or TEAM (from CODEOWNERS line NUMBER)." [About code owners](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners#about-code-owners) The line number tells you which line won. When you open a pull request, GitHub also lists the code owners it will request. [CODEOWNERS improvements changelog](https://github.blog/changelog/2022-02-17-codeowners-improvements-syntax-errors-preview-of-who-will-be-requested-and-more/)

For a whole file, a linter helps. Grafana runs the community tool [codeowners-validator](https://github.com/mszostok/codeowners-validator) on pull requests with its experimental `avoid-shadowing` check enabled. [grafana/grafana codeowners-validator.yml](https://github.com/grafana/grafana/blob/main/.github/workflows/codeowners-validator.yml), read on 2026-11-23. The tool's README describes that check as reporting "if entries go from least specific to most specific. Otherwise, earlier entries are completely ignored." A shadowing check flags order; it cannot tell you whether a team was meant to lose a path.

## What ordering does not catch

The last-match rule decides who is requested, not whether that person or team is right for the code. A correctly ordered file can still name a team that has left the area, or one without write access, which GitHub skips without blocking anything. [Audit CODEOWNERS errors](/learn/codeowners-errors-before-requiring-review/) before relying on it. A pattern can also match more or fewer files than you meant, which is a separate mistake from order; [choosing a directory pattern](/learn/codeowners-directory-patterns/) covers that.

## The cost of getting order wrong

A shadowed line costs nothing visible. Review requests go to the later team, the required approval is met by that team, and the merge goes through. The team that lost the path finds out only when it notices changes it never saw. The opposite mistake, a broad line placed last by accident, adds friction instead: one team is asked to approve everything under a large directory and starts approving without reading.

## How to order the file

Write the file so that position carries intent:

1.  Put the default owner, `*`, first.
2.  List directories from shallow to deep. Grafana's header describes this convention: "In each subsection folders are ordered first by depth, then alphabetically. This should make it easy to add new rules without breaking existing ones." [grafana/grafana .github/CODEOWNERS](https://github.com/grafana/grafana/blob/main/.github/CODEOWNERS), read on 2026-11-23.
3.  Put deliberate overrides and carve-outs in a final section with a comment that names what they take and from whom. CPython does this for its exclusions, which "should go at the very end because the final matching pattern will take precedence." [python/cpython .github/CODEOWNERS](https://github.com/python/cpython/blob/main/.github/CODEOWNERS), read on 2026-11-23.
4.  When two teams should both be requested for a path, write them on one line after any broader pattern, for example `/deps/v8/ @nodejs/v8-update @nodejs/security-wg`. Either team's approval then satisfies the requirement, as [the guide to multiple owners](/learn/codeowners-any-owner-approves/) explains.

Before you turn on **Require review from Code Owners**, hover over one file in each team's area and confirm the tooltip names the line you expect.

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [Choose the CODEOWNERS pattern that matches a team's directory](/learn/codeowners-directory-patterns/)
    
    Code review The Proofline team November 23, 2026 4 min read
    
-   ### [When should a CODEOWNERS path have no owner?](/learn/codeowners-path-with-no-owner/)
    
    Code review The Proofline team November 23, 2026 4 min read
