GitHub
Forking
Branching
Version Control
Software Development

Forking vs. Branching in GitHub

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

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:

bash
1git clone [email protected]:acme/shop-app.git
2cd shop-app
3git switch -c feature/login-form
4printf '\nLogin form notes\n' >> README.md
5git add README.md
6git commit -m "Add login form notes"
7git push -u origin feature/login-form

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:

  1. fork the repository on GitHub
  2. clone your fork
  3. add the original repository as upstream
  4. create a branch in your fork
  5. open a pull request back to upstream

Example:

bash
1git clone [email protected]:yourname/project.git
2cd project
3git remote add upstream [email protected]:original-owner/project.git
4git fetch upstream
5git switch -c docs/fix-install-guide upstream/main

After you commit and push, the branch lives in your fork, not in the upstream repository:

bash
git push -u origin docs/fix-install-guide

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:

bash
1git fetch upstream
2git switch main
3git merge upstream/main
4git push origin main

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 upstream after 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
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track 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.

Browse interview questions

All Rights Reserved.