Fork
In short
A fork is a personal copy of someone else's repository on a hosting platform, letting you experiment freely and propose changes back to the original project.
What is a fork in Git?
A fork is a complete copy of a repository, including its files, branches, and history, created under your own account on a hosting platform such as GitHub, GitLab, or Bitbucket. You have full control over your fork, so you can make any changes you like without needing permission from the original project's owners. The original repository is usually called the upstream.
Forking is the standard way to contribute to open-source projects where you don't have write access. You fork the project, clone your fork to your computer, make changes on a branch, push them to your fork, and then open a pull request asking the upstream maintainers to merge your work. To keep your fork current, you add the original project as a remote named upstream and regularly bring in its new commits.
A fork is like photocopying a published cookbook so you can write in the margins and test new recipes. If one of your changes turns out great, you can send it to the original author, who decides whether to include it in the next edition. Sometimes a fork grows into a separate project of its own, usually when a community disagrees with the original's direction, as when LibreOffice was forked from OpenOffice.org.
A fork is often confused with a clone or a branch. A clone is a copy of a repository on your local machine, made with git clone, while a fork is a server-side copy under a different account. A branch is a separate line of work inside the same repository, so teams that share one repository usually use branches instead of forks.
Key takeaways
- A fork is a copy of a repository under your own account on a hosting platform.
- Forks let you contribute, through pull requests, to projects you can't push to directly.
- The original repository is called the upstream; sync with it to stay up to date.
- Forking is a hosting platform feature, not a Git command.
Example
# After forking on the hosting platform, clone YOUR fork
git clone https://github.com/your-name/project.git
cd project
# Add a second remote that points at the original repository
git remote add upstream https://github.com/original-owner/project.git
# Keep your fork up to date with the original
git fetch upstream
git switch main
git merge upstream/main
git push origin mainReaders ask
What is the difference between a fork and a clone?
A fork is a copy of a repository created on a hosting platform under your account. A clone is a copy downloaded to your own computer; in a typical workflow, you fork a project and then clone your fork.
What is the difference between a fork and a branch?
A branch is a separate line of development inside the same repository, and creating one there requires write access. A fork is an entirely separate repository that you own, which is why forks are used to contribute to projects where you can't create branches.
How do I keep my fork up to date?
Add the original project as a remote with git remote add upstream <url>, then run git fetch upstream and merge or rebase upstream/main into your branch. Many hosting platforms also offer a sync button that does this for you.
Often compared
See also
- RepositoryVersion Control, p. 34A repository is the storage location for a project, holding all of its files plus the complete history of every change recorded by a version control system.
- Pull RequestVersion Control, p. 32A pull request is a proposal to merge changes from one branch into another, giving teammates a place to review, discuss, and test the code before it is merged.
- BranchVersion Control, p. 2A branch in Git is an independent line of development that lets you work on a feature or fix in isolation, without affecting the main code until you merge it.
- GitVersion Control, p. 10Git is a free, open-source distributed version control system that tracks changes to files over time, so developers can collaborate and undo mistakes.
- MergeVersion Control, p. 29A merge in Git combines the changes from one branch into another, joining separate lines of development back together into a single, shared history.
Spotted a mistake or something missing on this page?Suggest an edit