Skip to main content

Side by side

ForkvsBranch

What is the difference between a fork and a branch?

Updated 2 min read7 differences

In short

A fork is a full copy of a repository under another owner, used to contribute where you can't push, while a branch is a separate line of work in the same repo.

Fork

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.

Read the page on Fork

Branch

A 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.

Read the page on Branch

Fork and Branch compared

AspectForkBranch
What it isA full copy of a repository under another ownerA named line of work inside one repository
Where it livesA separate repository on the hosting platformInside the same repository as the main code
PermissionsYou have full control over your copyNeeds write access to the repository
Created withA button or API call on the hosting platformgit branch or git switch -c
Staying currentFetch from an upstream remoteMerge or rebase from the main branch
Visibility of workSeparate from the original until a pull requestVisible to everyone with access to the repository
Best forOpen-source contributions and independent variantsFeatures, fixes and experiments within a team

The difference, explained

A fork is a full copy of someone else's repository, including its branches and history, created under your own account on a code hosting platform. A branch is a movable pointer to a commit inside a Git repository, letting you work on a feature or fix without touching the main line of code.

The difference is ownership and permissions. Branches live in one repository and are shared by everyone with write access, which suits a team working together. A fork gives you your own repository with full control, which is how people contribute to open-source projects they cannot push to: they change their fork and open a pull request back to the original, often called upstream.

Forks and branches are used together. Inside a fork, you still create a branch for each change, and the pull request asks to merge that branch into a branch of the upstream repository. To keep a fork current, you add the original as a remote named upstream and fetch its changes.

A common misconception is that forking is a Git command. Git itself only has clones, branches and remotes; forking is a feature of hosting platforms that makes a server-side copy and remembers the link back to the original.

Which one should you use?

Choose Fork when…

  • You don't have write access to the original repository.
  • You are contributing to an open-source project.
  • You want to start an independent version of a project.

Choose Branch when…

  • You are on the team and can push to the repository.
  • You are building a feature or fix that will merge back soon.
  • You want to experiment without leaving the project.

Contributing through a fork or a branch

Forkbash
# After forking on the hosting platform, clone your copy
git clone https://git.example.com/you/project.git
cd project

# Link the original repository to stay in sync
git remote add upstream https://git.example.com/owner/project.git
git fetch upstream
git merge upstream/main
Branchbash
# Work on a branch inside the same repository
git switch -c fix-login
git commit -am "Fix login redirect"
git push -u origin fix-login

# Then open a pull request from fix-login into main

Readers ask

Should I fork or branch?

Branch if you have write access to the repository, which is typical inside a team. Fork if you don't, as with most open-source projects, and send your changes back through a pull request.

Is a fork the same as a clone?

Not quite. A clone is a copy on your own machine, while a fork is a server-side copy under your account that keeps a link to the original repository.

Can a fork have branches?

Yes. A fork is a full repository, so you create branches in it as usual, and pull requests are usually opened from one of those branches.

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

More

Settings