Open source · Licensing
Software Licenses Explained: MIT, Apache 2.0, GPL and How to Choose One for Your GitHub Project
Every public repository carries a question that nobody asks out loud: what am I allowed to do with this code? A software license is the answer. It is a short legal document, usually a file called LICENSE in the root of the repository, that tells other people what they may do with your source code. This post explains what licenses are, reads the MIT license line by line, compares the licenses you will meet most often, and helps you choose one for your next project.
- A license tells other people whether they may use, change, share and sell your code, and under which conditions.
- Making a repository public does not make it open source. With no license, you keep all rights and others have no permission to reuse your code.
- Permissive licenses (MIT, BSD, Apache 2.0) let people do almost anything if they keep your notice. Copyleft licenses (GPL, LGPL, MPL) also ask people to share their changes under similar terms.
- MIT is short and simple. Apache 2.0 adds an explicit patent grant. GPL keeps derivative works open.
- For learning and sample projects, MIT or Apache 2.0 is usually the easy, safe choice.
- MIT does not make people credit you in their app. They only have to keep the copyright and license notice with the code.
- Your license does not change the license of the libraries you depend on.
- This is a general explanation, not legal advice.
Contents
- What a software license is, and why code without one is not open source
- A worked example: the MIT license, line by line
- The licenses you will meet most often
- Permissive or copyleft: what changes in practice
- Which license should you choose?
- LICENSE, COPYRIGHT and NOTICE: what each file is for
- Your license and your dependencies
- Add a license to your GitHub repository
- Common mistakes
- Takeaways and glossary
Not legal advice. I am a software engineer, not a lawyer. This post explains the ideas in plain words so you can read a license with confidence and pick a sensible one. For a company product, a contract, or a dispute, ask a qualified lawyer.
1. What a software license is, and why code without one is not open source
A software license is a legal document that defines what other people are allowed to do with your source code when you publish a project. When you put an Android app, a Kotlin library, a Java application or any other project on GitHub, the LICENSE file tells other developers whether they can:
- Use your code in their own projects.
- Modify your source code.
- Distribute your application.
- Use your code commercially.
- Include your code in proprietary or closed-source products.
- Redistribute modified versions, and under which conditions.
No license does not mean free to use
The law gives you copyright over the code you write, automatically, the moment you write it. You do not need to register anything. So if you publish a repository with no license, the default is “all rights reserved”: nobody else may copy, change or redistribute your code without asking you.
Making the repository public changes only one thing: people can see it. GitHub’s terms let other GitHub users view and fork a public repository on GitHub, but that is all. A public repository without a license is not open source, and a careful developer or company will avoid copying it.
Analogy. Think of a photograph on a website. You can look at it. But unless the photographer says how it may be reused, you cannot print it in your own book. A license is the photographer’s note that says, “you may reuse this, if you do X.”
“Open source” also has a formal meaning. The Open Source Initiative (OSI) publishes the Open Source Definition, and a license counts as open source when it allows people to use, study, change and share the software freely. MIT, BSD, Apache 2.0, GPL, LGPL and MPL are all on OSI’s list of approved licenses.
2. A worked example: the MIT license, line by line
The MIT License is one of the most popular permissive open-source licenses, and it is a good first license to learn because it is so short. When a repository’s LICENSE file contains the MIT License, other developers can do all of this:
| What someone may do | Allowed? |
|---|---|
| View the source code | Yes |
| Copy the code | Yes |
| Modify the code | Yes |
| Use it commercially | Yes |
| Include it in a paid application | Yes |
| Redistribute it | Yes |
| Use it in closed-source projects | Yes |
| Sell software that contains the code | Yes |
The conditions are short:
- They must keep the copyright notice.
- They must include the MIT license text when they distribute copies or substantial portions of the software.
- The author provides the software without any warranty.
In simple terms: people can use the code, even inside a commercial product, without asking the author for permission, as long as they follow the license. Here is the full text, with placeholders for the year and the copyright holder:
MIT License
Copyright (c) <year> <copyright holder>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Reading it line by line
| The license says | In plain words |
|---|---|
Copyright (c) <year> <copyright holder> | Who owns the copyright, and since which year. You fill in your own name and year. This is the notice that must travel with the code. |
Permission is hereby granted, free of charge | You do not pay the author and you do not need to ask. |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | The list of permissions. Merge means combining it with your own code. Sublicense means you can pass the code on inside your own project, under your own terms, as long as the notice stays. |
The above copyright notice and this permission notice shall be included | The one real condition. Keep the notice with copies and with substantial portions of the code. |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY | No promises. If the code has a bug or loses your data, you cannot hold the author responsible. |
3. The licenses you will meet most often
Licenses fall on a spectrum. On the left are licenses that ask almost nothing of the people who reuse your code. On the right are licenses that require derivative work to stay open too.
MIT: very permissive
People can use, modify, distribute and sell the code, including inside closed-source software. They keep the copyright and license notice. It is short enough to read in a minute. Examples: React and Express.js.
Apache 2.0: permissive, with patent protection
Similar to MIT, but it also gives an explicit patent grant: people who contribute code license any patents that cover their contribution, which protects users from patent claims by contributors. It also has extra duties: keep the notices, and mark the files you changed. Examples: Kubernetes, Kotlin and AndroidX.
BSD 2-Clause and 3-Clause: permissive
Very close to MIT. Commercial use and redistribution are allowed with the copyright and license notices. The 3-Clause version also forbids using the contributors’ names to promote a derived product without permission.
GPL 3.0: strong copyleft
You can use, modify and distribute the software, and even sell it. The catch: when you distribute a derivative or a combined work, you generally have to offer the corresponding source code under the GPL as well. That keeps improvements open, and it also makes GPL code hard to use in closed-source products. Examples: GIMP and the Linux kernel (which uses GPL version 2).
A close relative is the AGPL, which treats software offered over a network (a web service, for example) like distributed software.
LGPL 3.0: copyleft for libraries
Designed for libraries. A proprietary application can generally use an LGPL library, with conditions such as allowing users to replace or relink the library. Changes to the library itself have to be shared.
MPL 2.0: file-level copyleft
If you change a file that is covered by the MPL, and you distribute it, that file must stay under the MPL. But you can combine MPL files with your own proprietary code in a larger application. It is a middle path between MIT and GPL. Example: Firefox.
Unlicense and CC0: public-domain dedications
These try to give up copyright restrictions as far as the law allows. How well that works depends on the country, which is why some people prefer a permissive license like MIT instead.
4. Permissive or copyleft: what changes in practice
The practical question is what happens when someone else builds on your code. This table is a simplified summary, so read the real license before relying on it.
| License | Can it go into a closed-source app? | Must changes be shared? | Explicit patent grant? |
|---|---|---|---|
| MIT | Yes | No | No |
| BSD 2/3-Clause | Yes | No | No |
| Apache 2.0 | Yes | No (keep notices, mark changed files) | Yes |
| MPL 2.0 | Yes, as part of a larger work | Yes, for the MPL-covered files | Yes |
| LGPL 3.0 | Yes, when used as a library, with conditions | Yes, for the library itself | Yes |
| GPL 3.0 | Generally no: the combined work becomes GPL when distributed | Yes, when distributing | Yes |
Every one of these licenses has conditions. Even MIT has one: keep the notice. “Open source” means you may reuse the code, not that you may ignore the license.
5. Which license should you choose?
Start from your goal, not from the license names.
| Your intention | Good fit |
|---|---|
| Anyone can reuse the code, no fuss | MIT |
| Commercial use, plus an explicit patent grant | Apache 2.0 |
| Improvements must always stay open source | GPL 3.0 |
| An open-source library that proprietary apps may still use | LGPL 3.0 |
| Others may change your files, but the files stay open, and larger projects can stay proprietary | MPL 2.0 |
| Give up your rights as far as the law allows | Unlicense or CC0 |
For educational Android, Kotlin and Java projects, such as architecture examples (MVC, MVP, MVVM, MVI, Redux, VIPER), small apps and tutorials, I would choose MIT. Choose Apache 2.0 instead if you want the explicit patent grant and do not mind the extra notice rules.
Questions to ask yourself
- Do I mind if a company uses this in a closed product? If not, pick a permissive license. If yes, look at the GPL family.
- Could patents be involved? If yes, Apache 2.0 (or MPL, or GPL 3.0) spells out the patent permission. MIT does not mention patents.
- Is it a library or an application? Libraries that you want widely adopted usually use a permissive license or the LGPL.
- Are other people contributing? Pick the license before accepting contributions. Changing it later usually needs everybody’s agreement.
6. LICENSE, COPYRIGHT and NOTICE: what each file is for
| File or line | Purpose |
|---|---|
LICENSE | The legal permissions and restrictions. This is the file GitHub looks for, and it shows the license name on the repository page. |
| Copyright line | Who owns the copyright and from which year. In the MIT license it is the first line, Copyright (c) 2026 Your Name. Some projects also keep a separate COPYRIGHT file. |
NOTICE | Often used with Apache 2.0 to carry attribution and other notices that must be passed on with the software. |
| SPDX header | A one-line tag at the top of a source file that names its license, for example // SPDX-License-Identifier: MIT. Tools can read it. |
Also mention the license in your README, with a link to the LICENSE file. People read the README first.
7. Your license and your dependencies
A repository can contain or use third-party code that has different licenses. Putting an MIT license on your repository does not change the license of those libraries. Each dependency stays under its own terms, and you have to follow them.
For an Android app this matters a lot, because a typical project pulls in dozens of libraries, and many of them (AndroidX, Kotlin, OkHttp, for example) use Apache 2.0, which asks you to keep their notices. That is why many apps have an “Open source licenses” screen; Google’s OSS licenses Gradle plugin can generate one for you.
Can I mix code under different licenses?
| Situation | Usually |
|---|---|
| MIT, BSD or Apache 2.0 code inside a GPL 3.0 project | Fine. Keep their notices. |
| GPL code inside an MIT project that you distribute | The combined work must follow the GPL, so the “MIT project” stops being only MIT. |
| Apache 2.0 code and GPL 2.0-only code together | Not compatible. Apache 2.0 and GPL 3.0 are compatible. |
| Code with no license | Do not copy it. You have no permission. |
When in doubt, check the dependency’s license before you ship, and keep a list of what you use.
8. Add a license to your GitHub repository
On the GitHub website
- Open your repository and choose Add file, then Create new file.
- Type
LICENSEas the file name. GitHub then shows a Choose a license template button. - Pick a license, fill in your name and the year, and commit the file.
When you create a new repository, you can also choose a license in the creation form.
From the command line
# Copy the text of the license you chose into a file called LICENSE, then:
git add LICENSE
git commit -m "Add MIT license"
git push
GitHub detects standard license files and shows the license name in the repository sidebar. For a Maven or Gradle library, also declare the license in the build metadata, for example in pom.xml:
<licenses>
<license>
<name>MIT License</name>
<url>https://opensource.org/license/mit</url>
</license>
</licenses>
9. Common mistakes
- Publishing with no license and assuming people may reuse it. They may not.
- Copying a license and leaving someone else’s name and year in the copyright line.
- Believing MIT forces people to credit you in their app. It only requires keeping the notice with copies and substantial portions of the code. Nobody has to mention your name on a splash screen or your GitHub profile.
- Pulling GPL code into a permissive project without noticing what that does to the whole combined work.
- Forgetting dependencies. Your license covers your code, not theirs.
- Expecting to take rights back. If you change the license later, people who already received the code under the old one generally keep the rights they were given.
- Assuming a license covers names and logos. Most software licenses are about the code. Trademarks are a separate matter, and Apache 2.0 says so explicitly.
10. Takeaways and glossary
- No license means “all rights reserved”, even on a public repository.
- Permissive licenses (MIT, BSD, Apache 2.0) ask for little. Copyleft licenses (GPL, LGPL, MPL) ask for shared changes.
- MIT or Apache 2.0 is a good default for educational and sample projects.
- Add the
LICENSEfile before you accept contributions, and mention it in the README. - Your license covers your code, not your dependencies. Check theirs.
- For anything that matters commercially, ask a lawyer.
| Term | In plain words |
|---|---|
| Copyright | The automatic legal right of the author to control copying and reuse of their work. |
| License | The author’s written permission to do certain things with the work, under stated conditions. |
| Open source | Software under a license that lets everyone use, study, change and share it. |
| Permissive license | A license with few conditions, mainly “keep the notice” (MIT, BSD, Apache 2.0). |
| Copyleft | A license that requires derivative work to be shared under similar terms (GPL, LGPL, MPL). |
| Derivative work | New work built from, or including, existing code. |
| Proprietary / closed source | Software whose source code is not shared and whose use is restricted by its owner. |
| Patent grant | A promise not to sue users over patents that cover the code you contributed. |
| Attribution | Keeping the required copyright and license notices with the code. |
| SPDX identifier | A standard short name for a license, such as MIT or Apache-2.0. |
Links and further reading
- Choose a License (GitHub’s plain-language guide) · What happens with no license
- GitHub Docs: Licensing a repository
- Open Source Initiative: licenses · The Open Source Definition
- SPDX license list (standard identifiers)
- License texts: MIT · Apache 2.0 · GPL 3.0 · MPL 2.0 · Unlicense · CC0