Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags


How to work with Git forks

Anjana Shankar

Forking the repository is one way to collaborate on projects in Github. This is especially useful when you do not have write access to the original repository. It allows you to contribute to the repository along with allowing the owner(s) to have control over who can write to the repository.

When working with open source projects, Forking the repository and working with it is the only solution in these situations.


Go to the repository you would like to fork. On Github, it looks like the picture shown below. Forking a repository creates a copy of the repository and allows you to make changes to it without affecting the upstream repository.


Forking a repository will create a copy of the repository into your account. Now you can use this copy to work. The challenge lies in keeping it up to date with the upstream repository (original repository)

I will cover the steps that enable you to do this below.

Step 1

Clone the forked repository to your local machine.

# your_fork_url is the url of the repository copy in your account.
git clone <your_fork_url>

Step 2

Set your upstream to be able to pull down updates from the master repository.

# upstream_git_repo_url is the url of the original repo on github.
git remote add upstream <upstream_git_repo_url>

Step 3

Verify the upstream was added. You can use -v to verify if the upstream was added.

 git remote -v
 # This lists the urls as shown below
origin (fetch)
origin (push)
upstream (fetch)
upstream (push)

Step 4

Lastly, update the git repo from the master by the following commands:

git fetch upstream
git merge upstream/master

Forking vs Cloning

Forking is something you do on the Github Account while Cloning is a git operation. Irrespective of whether you fork the repository or not, you need to clone the repository in order to effectively work on it.

A more detailed explanation can be found here in this edpresso shot by Arash



View all Courses

Keep Exploring