Also called File ownership, Code authorship, Primary owner
In depth Code ownership and bus factor from git: the full method, edge cases and what to do about a bus factor of 1.
How code ownership is measured
Two measures are in common use, and they answer different questions.
- Line ownership: each author's share of the lines that exist today, from
git blame. It shows who wrote the current code. - Commit ownership: each author's share of the commits that touched the file. It shows who maintains it.
Example for billing/invoice.py (500 lines, 50 commits):
| Author | Lines (blame) | Commits |
|---|---|---|
| Priya | 60% | 41 |
| Sam | 30% | 6 |
| Lee | 10% | 3 |
Priya is the owner by both measures here. The two can split: someone who rewrote the file in one large commit holds most lines but few commits. A recent owner, the most active author over the last 90 days, can also differ from the all-time owner.
Why code ownership matters
Ownership tells you who to ask, who should review, and where knowledge is concentrated. Bird, Nagappan, Murphy, Gall and Devanbu, "Don't Touch My Code! Examining the Effects of Ownership on Software Quality" (FSE 2011), studied Windows Vista and Windows 7 and found that components with many low-ownership contributors had more pre-release and post-release failures. The practical reading: someone should clearly own each important file, and a second person should be able to maintain it (see bus factor).
Declared and measured ownership drift apart. People leave, teams reorganise, and a CODEOWNERS entry keeps naming them. Measured ownership shows the drift.
How to measure code ownership yourself
# Who owns the lines that exist now
git blame --line-porcelain billing/invoice.py | grep '^author ' | sort | uniq -c | sort -rn
# Who made the commits
git shortlog -sn --no-merges -- billing/invoice.pyAdd -w and -M to git blame to ignore whitespace changes and detect moved lines. git-fame summarises line ownership per author for a whole repository. CODEOWNERS is the right tool when you need enforced review: GitHub and GitLab read it to require approvals from named owners. The code ownership tools roundup compares measured-ownership tools.
How repowise measures code ownership
During git indexing repowise records per file a primary owner, a recent owner and the top authors.
- Primary owner: the author with the largest share of current lines from one
git blame --line-porcelainpass (files up to 100 KB, best effort).primary_owner_line_pctis their line share andprimary_owner_commit_pcttheir share of the file's commits. If blame is unavailable, the author with the most commits is used. Pure file moves do not count as authoring. - Recent owner: the top author over the last 90 days and their share of recent commits.
- Fading ownership: a code health detector fires when a file is still changing, has bus factor 1, and its primary owner is not the recent owner or contributes under 20% of recent commits. Stable files never fire it.
- Suggested reviewers: a score that blends ownership of the touched files (weight 1.0), ownership of their co-change partners (0.5) and recent activity (0.4). See temporal coupling.
- CODEOWNERS: repowise parses GitHub and GitLab CODEOWNERS files, so declared and measured owners can be read side by side.
Owners appear in get_context and get_risk over MCP and in repowise context <file>. They come from git, with no model involved. See git intelligence.