Forking vs. Branching in GitHub
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Forking and branching both let you change code without touching the default branch directly, but they solve different collaboration problems. Branching is usually what you do inside a repository you already have write access to, while forking is what you do when you need your own copy of someone else's repository.
Branching: Work Inside the Same Repository
A branch is just another line of development in the same Git repository. The repository owner, issues, pull requests, and permissions all stay in one place. This is the normal workflow for a team that already shares access to the project.
Create a feature branch locally and push it to the same repository:
That branch now exists under the original repository. Teammates with access can review it, push more commits to it, or merge it into main.
Branching is usually the right choice when:
- you work in a private company repository
- your team already has push permission
- you want short-lived feature branches and fast pull requests
- you need shared CI, branch protection, and code review in one place
Forking: Work in Your Own Copy
A fork is a repository-level copy under your own GitHub account or organization. It is still connected to the original project for pull request workflows, but it has separate ownership and permissions.
Forking is common in open source because contributors usually do not have direct push access to the upstream repository. The usual pattern is:
- fork the repository on GitHub
- clone your fork
- add the original repository as
upstream - create a branch in your fork
- open a pull request back to upstream
Example:
After you commit and push, the branch lives in your fork, not in the upstream repository:
This model gives you freedom to experiment without asking for write access first.
The Practical Difference
The easiest way to think about it is scope.
- a branch is inside one repository
- a fork is another repository
That difference changes several things:
- Permissions: branches rely on existing write access, forks do not.
- Ownership: a fork belongs to you; a branch belongs to the repository that hosts it.
- Maintenance: forks may need to be synced with upstream over time.
- Collaboration style: branches are ideal for internal teamwork, forks are ideal for outside contributions.
If you already have access to the repository, using a branch is usually simpler. If you do not, a fork is usually the correct entry point.
Keeping a Fork Up to Date
One extra task with forks is synchronization. The upstream project keeps moving, so your fork can drift behind. A common maintenance step is fetching from upstream and rebasing or merging:
If your team works entirely inside one repository, branching avoids that extra layer of maintenance.
When GitHub Features Matter
GitHub pull requests work with both models, but there are workflow differences:
- branch-based pull requests are simpler for internal teams
- fork-based pull requests are safer for external contributions
- maintainers can choose whether to allow edits from upstream on a forked pull request
That means the decision is often less about Git itself and more about repository governance. Open source communities prefer forks because they protect the main repository from uncontrolled direct pushes. Internal teams usually prefer branches because the code, automation, and permissions stay centralized.
Common Pitfalls
- Using a fork when a normal branch would be simpler for an internal team. That adds unnecessary remotes and sync work.
- Creating a branch in the wrong repository and then wondering why the pull request target looks strange.
- Forgetting to add
upstreamafter cloning a fork, which makes it harder to pull in new changes from the original project. - Treating a fork like a branch. They are not interchangeable because one changes repository ownership and permission boundaries.
- Letting a long-lived fork drift too far from upstream, which makes later rebases and merges painful.
Summary
- Branching means creating another line of development inside the same repository.
- Forking means creating your own repository copy and contributing from there.
- Use branches when you already have write access and want a simple team workflow.
- Use forks when you need isolation or when contributing to a repository you do not control.
- In GitHub, the best choice usually follows repository permissions more than personal preference.
Related reading
- Generating statistics from Git repository
- Get all files that have been modified in git branch
- Get changes from master into branch in Git
- Get changes from master into branch in Git
- Get source JARs from Maven repository
- Get the creation date of a stash
- Get the current git hash in a Python script
- Get the short Git version hash
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.