Difference Between Forking and Branching on GitHub

John Wachira Oct 27, 2022
Difference Between Forking and Branching on GitHub

This article discusses the difference between forking and branching on GitHub. In the context of coding, the current era is more dependent on collaboration.

One of the most used collaboration tools is GitHub. Forking and branching on GitHub are some of the most useful utilities when collaborating on projects.

However, the two have different use cases and implications, as discussed below.

Difference Between Forking and Branching on GitHub

Forking on GitHub involves creating a copy of a public repository in your personal account. This concept encourages the divergent evolution of a codebase.

Divergent evolution is ideal for those looking to experiment broadly on a theme.

On the other hand, branching involves creating a branch from the origin. It encourages the convergent evolution of a codebase.

Most business enterprises prefer branching since it positively affects a team’s productivity.

Divergent vs Convergent Evolution

You have probably noticed that in the open-source world, a codebase may split into two projects simultaneously. Take the example of the Linux codebase.

We now have several forks, like Linux RedHat, but they all have a shared ancestry. This is an example of the divergent evolution of a codebase.

It is worth noting that these iterations are not temporary development paths and will never integrate into each other.

On the other hand, branches are temporary development paths. Branches are short-lived as they are done with when the code is merged to the master branch.

That is why they encourage the convergent evolution of a codebase.

Forking Creates a New Repository

GitHub makes it easy to fork with just a press of a button. This action creates a duplicate of the repository up to the time of forking.

fork on github

When is it ideal to fork?

It’s when you want to create an independent project without intending to reunite it with its parent.

You may come across a project on GitHub that is a great starting point for your project. At such a juncture, forking will be ideal.

Branching on GitHub

Branches play the role of construction zones in a codebase. We use branches temporarily to work on features with the intent of merging with the origin.

To create a branch on GitHub, go to View all branches and hit New Branch.

create a branch in github

To create a new branch locally, we use the git checkout command, as illustrated below.

$ git checkout -b <new branch>

What Is the Cost of Forking and Branching

It is easier and faster to merge a branch since Git will only compare the changed files. On the other hand, forking can be thought of as more expensive.

When merging a fork with its original parent, Git has to compare two repositories. Remember that forking creates a duplicate of the entire parent repository.

The file size of your new branch will vary depending on the parent branch. Forks take up more space on your remote server.

Branching is encouraged for a business enterprise since there will be more visibility and less operational risk.

Here is why:

Let’s say we have a team of ten working on a different feature in the project. When each developer creates a fork, we will have ten different and independent repositories.

This will make it hard to see what everyone is working on unless you have all ten repos in one place.

This is not a true collaboration environment since code changes live in ten different repos.

If the developers opted for ten different branches rather than forking, it would be more of a collaborative space as all the commits are in one repository. This argument caters to the issue of visibility.

When we talk of operational risk, take this example: developers have created ten forks, and one or two are unavailable for some reason. This introduces the risk of knowledge management, where other developers will not know where the other developer has reached.

It is not always the case, but it is still a risk that can be avoided by going for a branch-centric workflow.

A branch-centric workflow is best suited for a business setting, while forking works best for public collaboration and experimentation. If you are all working towards one goal, go for a branch-centric workflow.

Author: John Wachira
John Wachira avatar John Wachira avatar

John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.


Related Article - Git Fork

Related Article - Git Branch