How Forking Works in Open Source?

In short
Forking means making your own copy of someone else's project so you can change it without touching the original. On GitHub, a fork lives in your account, and you can propose your changes back to the original project through a pull request.
What a fork is
A fork is a copy of a repository that lives under your own account or organization. The original project is called the upstream repository. Your copy is linked to it, but your changes stay in your copy until you decide to share them. That means you can experiment, fix a bug, or add a feature without putting the main project at risk.
Forks are the usual way to contribute to open source on GitHub. You do not need permission from the project owners to make a fork of a public repository. You only need write access to your own fork to push changes to it.
How to create a fork
On GitHub, open the repository page and click Fork in the top-right corner. Then choose the owner for the new copy. You can keep the default name or type a different one, and add an optional description. There is also an option to copy only the default branch. For most open source contributions, that is all you need, because other branches are usually not required for a fix. Click Create fork, and the copy appears under your account.
If you prefer the command line and have the GitHub CLI installed, you can run a single command:
gh repo fork REPOSITORY
To place the fork in an organization, add the --org flag with the organization name.
Cloning your fork and adding the upstream
A fork exists on GitHub, but its files are not yet on your computer. To work locally, clone your fork with Git. Copy the repository URL from your fork's Code button and run git clone with that URL in your terminal.
When you plan to propose changes to the original project, it helps to also point your local copy at the upstream repository. Run git remote -v to see the current remote, which is usually named origin and points to your fork. Then add the upstream with git remote add upstream followed by the original repository URL. Run git remote -v again to confirm that origin points to your fork and upstream points to the original project.
With both remotes in place, you can pull new changes from the original project into your local copy and keep your fork up to date. Keeping your fork in sync is good practice before you start a new change, so your work is based on the latest code.
Making changes and proposing them back
You can make any change in a fork. A common habit is to create a separate branch for each change. A branch lets you work on one idea without disturbing the main line of code. When the change is ready, push the branch to your fork and open a pull request. A pull request asks the original maintainers to review your changes and pull them into the upstream repository. They can accept, ask for edits, or decline.
Choosing a repository to fork
You can fork any public repository to your personal account or to an organization where you can create repositories. If you have access to a private repository and the owner allows forking, you can fork it too. Be aware that plan limits can apply. For example, GitHub Free does not allow forking a private repository into an organization.
Common mistakes
A frequent mistake is to forget the upstream remote. Without it, your local copy only knows about your fork, so you cannot easily pull in new changes from the original project. Another mistake is to make all your edits on the main branch. This makes it harder to keep your fork synced and to submit focused pull requests. Use a separate branch for each change instead.
Also remember that a fork is a separate copy. Changes in the original project do not appear in your fork on their own. You need to sync them yourself with Git commands.
Alternatives
If you only want to read or try code, you can clone the original repository directly, with no fork. Cloning gives you a local copy but no way to push to the project. If you are a maintainer with write access to the repository, you may not need a fork at all and can create branches in the original repository instead.
FAQ
Do I need permission to fork a public repository?
No. You can fork any public repository to your own account or to an organization where you can create repositories. The fork is your own copy, so you can change it freely.
What is the difference between a fork and a clone?
A clone is a local copy of a repository on your computer. A fork is a copy hosted on GitHub under your account. Usually you fork first, then clone your fork to work on it locally.
What does the upstream remote mean?
The upstream remote is a Git link that points to the original repository your fork came from. It lets you pull new changes from the original project into your local copy.
Does a fork update automatically when the original project changes?
No. Your fork does not receive new changes on its own. You need to fetch and merge changes from the upstream repository using Git commands.
Sources
This page is based on the official documentation below. Read it for full detail.
Forking projects — official documentation ↗