Skip to main content

Fork

Updated 2 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/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

Working with a fork and its upstreambash
# 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 main

Readers 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

Spotted a mistake or something missing on this page?Suggest an edit

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings