LicensePlain 中文 visits —
Home / Guides / Adding a licence
Guide

How to add a licence to a repository

A licence is not a file you drop in once. It is a claim attached to four places in a repository, and the first public release fixes it.

The four places

  1. LICENSE at the repository rootFull text, no extension. This is what GitHub, GitLab and npm read to label the project.
  2. The manifest field"license": "MIT" in package.json, license = "MIT" in pyproject.toml, <licenses> in a pom.xml. Use the SPDX identifier, not the full name.
  3. SPDX headers in source files// SPDX-License-Identifier: MIT on line one. Optional for MIT, close to mandatory in corporate repositories with mixed provenance.
  4. NOTICE, if the licence has oneApache-2.0 projects ship a NOTICE file listing attributions. It has to travel with the code.

The copyright line

Copyright (c) 2026 Your Name. The year can be a range, and multiple holders get multiple lines. Two things to get right:

  • If you wrote it at work, the holder is usually your employer, not you. Check before publishing.
  • Never delete an upstream copyright line when you fork. Adding yours above it is correct; replacing it is not.

“Or later” changes everything

GPL-2.0-or-later means recipients may take the code under GPL-3.0 as well. It is why old GNU projects remain compatible with newer ones, and it is the single most consequential choice after picking the licence itself.

The cost: you cannot withdraw it. Once a release says “or later”, that release stays usable under future licence versions forever.

You cannot relicense what you do not own

Changing a project's licence requires permission from every contributor whose code is still in the tree. Without a CLA or a DCO with relicensing rights, the practical options are: keep the old licence for the old code, or rewrite the contributed parts. This is the reason the 2021–2024 wave of relicensing was controversial rather than routine.

If you are starting a project and might sell it later, decide now. Adding a contributor licence agreement after the fact is much harder than adding MIT before the first commit.

Questions

Do I need a licence to make the code usable?

Yes. Without one, default copyright applies: nobody may copy, modify or distribute it, even though the code is public.

Can I use two licences for one project?

Yes — dual licensing is common (GPL plus a commercial licence, or MIT/Apache-2.0 per file). Say so explicitly in the README, because the default assumption is that one licence covers everything.

What about a CLA?

A contributor licence agreement transfers or licenses rights to the project owner. It is what makes later relicensing legally possible; it is also why some contributors refuse to sign one.

Written to be checkable against the licence texts themselves. Where this guide and a licence disagree, the licence wins.