Difference Between Forking and Cloning on GitHub

John Wachira Feb 15, 2024
Difference Between Forking and Cloning on GitHub

This article outlines the difference between forking and cloning on GitHub. If you are a regular GitHub user, you have probably come across these terms.

For beginners, forking and cloning on GitHub can be rather confusing. Both terms apply when we are interacting with public GitHub repositories.

Let’s discuss how the two differ.

Difference Between Forking and Cloning on GitHub

We will define and discuss how each term works and when we should apply them. Let’s start with Forking.

Forking on GitHub

Forking on GitHub involves creating a copy of a public repository in your own personal GitHub account. Why fork a repository on GitHub?

Let’s assume you have found a public GitHub repository with a project you would like to test out. You will need a copy of the code on your local machine.

If you find a bug in the code and manage to fix it, you can’t just push your changes to the public repository unless the owner permits you.

This is where forking comes into play. Once you have created a fork, you can make a local copy of the forked repository where you can make changes without affecting the original repository.

From there, you can create a pull request to the original repository, and if the owner deems the changes ideal, they can accept the pull request, and your code will be incorporated into the original repo.

This is one of the various use cases of forking. Another common use case of forking is when you are working on a project jointly with other developers.

Suppose your company decides to host the remote repository on GitHub. In that case, it is easier to create a fork of the repository, push to the fork and create pull requests rather than having multiple developers pushing to the same repository.

You can synchronize your local repo and fork with the original copy whenever changes are introduced to the original repository.

How do you fork on GitHub?

To fork a public GitHub repository, navigate to the repository and tap on the Fork icon, as illustrated below.

fork on github

A new tab will load where you can change the name and description of the fork. If you want to fork all the branches, uncheck the Copy the master branch only box and hit Create Fork.

You can then make a local copy of your forked repository, leading us to the next section.

Cloning on GitHub

We know that all development is done locally. You cannot work on a project without a local copy of the code on your machine.

This is where Cloning comes into play. Cloning creates a local copy of a remote repository in your local machine.

Once you have cloned, you can start tweaking the code and contribute to the original repository. How do you clone a repository?

In this example, we will pick off where we left off after creating a fork. We have seen that to create a local copy of our fork; we will have to clone it.

To clone our fork, first, copy the URL for your fork. The URL is under the Code tab, as illustrated below.

repo url

Copy the URL and launch Git Bash. Create a folder where you will clone the repository, as illustrated below.

$ mkdir myproject

Open the folder as shown below.

$ cd myproject

Use the git clone command to clone your repository, as illustrated below.

$ git clone https://github.com/User/Repository.git

Outcome:

cloning a repo

Cloning may take a while, depending on the repository size and your internet connection.

Here is a table that summarizes the differences between the two.

Fork Clone
It is a concept It is a process
Does not involve the use of commands Involves the use of the git clone command
We fork on the GitHub account We clone using Git
You can merge changes made to a fork with the original repo via pull request You can only merge changes made to a cloned repo with the original repo if you are the owner or approved contributor

In conclusion, you will come across the concept of forking and the cloning process when interacting with public repositories hosted on GitHub. The two operate differently and vary in use cases.

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.

LinkedIn

Related Article - Git Fork

Related Article - Git Clone