Key takeaways
- A fork is a separate repository on GitHub. A clone is a copy on your computer. A branch lives inside one repository.
- Fork when you cannot push to the project or want to build your own version of it.
- A fork is a snapshot. Sync it with upstream before each new piece of work.
- Forking is not anonymous: the original's fork count goes up and your account appears in its list of forks.
We have worked with social networks for more than 10 years, and one habit from that work applies here: every public action leaves a trace that someone reads. Forking is the clearest case on GitHub, because it is both a working tool for developers and a public signal of interest. This article covers the tool first and the trace second.
A fork is your own copy of someone else's repository
GitHub's documentation defines forks as repositories that start as copies of another repository, called the upstream repository. A fork has its own settings and permissions but stays connected to upstream. Open one and you will see the original named under the fork's title.
Two reasons to fork cover most cases. You want to fix or add something in a project where you have no write access, or you want to start your own version of a project and keep its history. Both start with the same button, and neither touches the original until you send a pull request.
Fork vs clone vs branch: pick by what you need to change
| Fork | Clone | Branch | |
|---|---|---|---|
| Where it lives | GitHub, in your account | Your computer | Inside one repository |
| Needs write access to the original | No | No, but you cannot push without it | Yes |
| Has its own issues, pull requests and Actions | Yes | No, it is only files | No, it shares the repository's |
| Best for | Contributing to or building on a project that is not yours | Reading or working on code locally | Team work in a repository you can push to |
GitHub's documentation puts the difference in one line: a branch is part of one repository, and a fork is a separate repository with its own settings and collaboration space. Each fork can have its own branches, members, issues, pull requests, Actions, projects, tags, labels and wikis.
The common follow-up is whether you need a clone after forking. Yes, if you want to edit on your computer. The fork exists on GitHub only, so you clone your fork and not the original. If you only want to read the code, clone the original and skip the fork.
Fork a repository in five steps
- Open a public repository. GitHub's practice repository
octocat/Spoon-Knifeis a safe one to try. - Press Fork at the top right.
- Choose the owner, which is your account or an organization where you can create repositories, and confirm or change the name. A checkbox lets you copy only the default branch.
- Press Create fork. You land on
{you}/Spoon-Knifewith the original shown under the name. - Clone your fork:
git clone https://github.com/{you}/Spoon-Knife.git. With GitHub CLI,gh repo fork octocat/Spoon-Knife --clonedoes steps 2 to 5 in one go.
There is no git fork command. Forking is a GitHub feature and not part of Git itself, which is why it happens on the website or through the CLI.
You can fork any public repository. A private repository can be forked only if its owner permits it, and a private repository cannot be forked to an organization on GitHub Free. Repository, organization and enterprise policies can narrow this further.
Keep your fork in sync with upstream
A fork is a snapshot of the moment you made it. New commits in the original do not appear in your copy by themselves. The quickest route is the Sync fork button on your fork's page. On your computer the same job takes four commands:
git remote add upstream https://github.com/octocat/Spoon-Knife.gitadds the original under the name upstream, once.git remote -vlists your remotes so you can confirm both origin and upstream.git fetch upstreamdownloads its new commits.git merge upstream/mainbrings them into your branch. Use rebase instead if you prefer a straight history.
Make syncing the first step of every work session. A change built on a stale copy is the usual reason a pull request arrives with conflicts.
Open a pull request from your fork
Create a branch in your fork for each change and keep your main branch equal to upstream. Commit, push the branch to your fork, and GitHub offers to open a pull request against the original. The maintainer can accept it, ask for changes or close it. After a request for changes, push more commits to the same branch and the pull request updates.
A pull request is optional. Plenty of forks never send one, because they are the start of a separate project. If you do send one from a personal account, you can allow the maintainers to push to your branch. That lets them rebase it or fix a small issue before merging. GitHub does not offer this for forks owned by an organization.
What a fork shows to everyone else
Forking is not anonymous. The fork counter on the original goes up by one and your account appears among its forks. The Stack Overflow question "What does it mean to fork on GitHub" has been viewed 98,431 times, and one answer there states the same fact: forking is not anonymous. A public repository's forks are public, and a fork's visibility cannot be changed on its own.
The forks page under Insights lists every fork with its owner, and the network graph shows how work spread. Maintainers read that page to see who is building on the project: a fork with recent commits, open pull requests and stars of its own is someone using the code, and a fork untouched since the day it was made is only a copy.
One security note from GitHub's documentation applies to your own work. Repositories in a fork network share Git data, so commits pushed to any of them can be reachable from the others, including upstream, even after a fork is deleted. Keep secrets out of every commit you push to a fork.
What the fork count says about a project, next to stars and watchers, is in stars vs forks vs watchers, and the Watch button has its own guide. If you want developers to build on your repository, GitWow members fork public repositories by hand from their own accounts, with no password or token, only a link. Get forks for your repository, or begin with stars. Our launch guide for GitHub projects covers the rest of the launch.