Articles
Published · November 18, 2026

Update Copyright Years and Version Headers Across a Project on January 1

Find every copyright header with git grep, preview a safe sed replacement, review the diff, and update the copyright year and version headers in one pass.

Also in: Español中文हिन्दी

Every January, the headers in your repo say last year. To update the copyright year, list the files that carry the old notice with git grep, run one anchored sed replacement, and read the diff before you commit. It takes about ten minutes, and the same loop covers version headers too.

A stale year breaks nothing in the build, but it makes a project look untended. One scripted pass beats hand edits, and you can repeat it next year. Below is the full routine, plus the mistakes that trip people up.

Quick answer

A copyright notice has three parts: the symbol or the word "Copyright", the year of first publication, and the owner's name. Wikipedia's summary of copyright notices adds that for works first published on or after March 1, 1989, using a notice is optional. So refreshing the year is a project habit or policy, not a requirement. If it matters legally for your project, ask a lawyer.

Plenty of projects refresh it anyway. LilyPond's contributor guide says that "at the start of each year, copyright notices for all source files should be refreshed" by running one command from the top of the source tree. Their script performs a regular expression substitution of the old year for the new one wherever it finds a valid notice.

Your version is three steps: list the files, replace the year, review the diff.

Step-by-step

1. Decide your notice style

Pick one line format and use it everywhere. For example:

Copyright (c) 2026 Your Name

Decide now whether you use a single year or a range such as 2021-2026. Mixed styles make later replacements messy.

2. List every file with a notice

Work on a clean branch so you can throw the result away. Then ask Git which tracked files carry the old line:

git grep -I -l "Copyright (c) 2026 Your Name"

Per the git grep manual, the command searches tracked files in the work tree. The -l flag prints only file names, and -I skips binary files. Because it only looks at tracked files, build output and node_modules stay out of the list.

3. Preview the change

Before editing anything, see the exact lines you are about to touch:

git grep -I -n "Copyright (c) 2026 Your Name"

Scan the list for files that shouldn't change, such as vendored code. If you spot any, read the next section first.

4. Apply the replacement

Match the whole notice, not just the year. That keeps a stray "2026" in a changelog or a test fixture untouched.

git grep -I -l -z "Copyright (c) 2026 Your Name" \
  | xargs -0 sed -i '' 's/Copyright (c) 2026 Your Name/Copyright (c) 2027 Your Name/'

The -z and -0 pair passes file names with spaces safely. One platform note: on macOS, sed -i needs an empty string after it, as shown. On GNU/Linux, write sed -i with no argument.

5. Review the diff

git diff --stat
git diff

Every changed line should be a notice line and nothing else. If the count of changed files matches the count from step 2, you're done. Commit it as a single commit so it's easy to find and revert.

6. Do the same for version headers

If your files carry a version string in a header comment, or you keep a VERSION file, reuse the loop. Search for the exact old string, for example Version: 3.2.0, preview it, replace it with the new one, and check the diff. Don't run a blanket replacement on 3.2.0 alone. It will also match dependency versions and lock files.

Common problems and fixes

Notices that name someone else. Anchor the pattern on your own name, as above. The copyright-updater project makes the same point: its README describes a config file that limits changes to notices carrying your name. Likewise, gnulib's update-copyright script only acts on a statement it recognizes whose final year is not the current year, and it warns about files where it finds none.

Year ranges. If a header says 2021-2026, replace the range, not a lone year: s/2021-2026/2021-2027/. Style differs between tools. The copyright-updater README shows 2008, 2009, 2010 collapsing into 2008-2010, while gnulib's script expands intervals by default and collapses them only when asked. Whichever you choose, apply it everywhere.

Vendored and copied files. Leave them alone. Their notices belong to someone else, and LilyPond's script deliberately skips copied third-party files such as texinfo.tex. In Git, exclude a folder with a pathspec:

git grep -I -l "Copyright (c) 2026" -- . ':!vendor/'

Binary and generated files. -I handles binaries. For generated files, regenerate them instead of editing them, so the next build does not undo your change.

Line endings and trailing newlines. sed can rewrite a file's final newline on some platforms, which shows up as noisy diffs. If that bites you, read why trailing newlines and line endings break parsers. For a wider tidy-up, see year-end cleanup for developers.

Doing this with Carets

Carets is a native notes and code editor for iPhone, iPad, and Mac. It handles Markdown, plain text, and code with syntax highlighting, organized into files, projects, and tags. The bulk replacement runs in your terminal. Carets covers the parts around it.

Keep a short "January checklist" file in a project: the exact notice line, the three commands above, and the paths to exclude. Tag it with something like yearly and it is easy to find on January 1. When you only need to confirm one header, open the file on your iPhone or iPad. Syntax highlighting makes the header comment easy to read, and a one-line fix takes seconds. Your files stay plain text, so the same checklist works on any machine. If you hand a project to someone before time off, a status file before time off is a good place to note the yearly routine.

Get Carets on the App Store for iPhone, iPad, and Mac.

Frequently Asked Questions

Do I have to update the copyright year every January?

Not necessarily. For works first published on or after March 1, 1989, a notice is optional in US law, and the year in a notice is the year of first publication. Many projects still refresh it each year by convention or by their own policy, so follow the policy your project or employer uses, and ask a lawyer if it matters legally.

Should I use a year range like 2021-2027?

Many projects do. Tools such as copyright-updater collapse lists like 2008, 2009, 2010 into 2008-2010, while gnulib's script expands intervals by default and collapses them only when asked. Pick one style and apply it everywhere.

Can I run the replacement on third-party code?

No. Leave vendored and copied files alone, because their notices belong to someone else. LilyPond's script skips copied third-party files such as texinfo.tex for this reason.

How do I check the result before committing?

Run git diff and scan it, or git diff --stat for a count of files. Every changed line should be a notice line and nothing else.