DEV Community

Cover image for Keeping your forked repo in sync with the remote repo

Posted on

Keeping your forked repo in sync with the remote repo

While using Git/Github, there's a need to be updated with the latest commits.

What is a fork and why is it needed?

Forking a repository means creating your own version of the repo where you can make whatever changes you want. It's like a personal copy. It won't affect the original product. With forks, you can change/modify whatever you want and experiment around code freely and fearlessly! Cool right? Forking has nothing to do with Git, it is a feature of Github. Thanks to this awesome feature otherwise we wouldn't be able to play around with code at such individual levels.


In cloning, the copy of the repository is made at your local machine unlike fork where the copy is restricted to a repository on Github only. This is the main difference between fork and clone.

Alt Text

Updating your forked repository

You started contributing to a project so you forked it, began working on an issue. In the mean time, other developers of the project pushed changes to the original repo from where you had forked. Now, you're done working and want to open a PR. When you go on Github, you see

This branch is 5701 commits behind original:master

Now, you need to update your forked repo
(Assuming you've cloned already)

  1. Switching to the master branch
    git checkout master

  2. Checking remote versions
    git remote -v

  3. Adding/Setting remote
    git remote add upstream link
    link is of the original repo from where you forked!
    upstream is the master branch of the original repo
    git remote set-url origin SSH of original repo

  4. Fetching all the changes from the upstream
    git fetch upstream

  5. Merging
    git merge upstream/master

  6. Finallyy pushing your changes
    git push

You're all set to open that PR!

Top comments (3)

abhijit2505 profile image
Abhijit Tripathy

Nice one

devtalhaakbar profile image
Muhammad Talha Akbar

I would suggest that you update the title of this post to make it clearer what your post is about.

forinda profile image
Orinda Felix Ochieng

Thanks for the brief. I was also wondering if someone updates his/her repository does it affect your forked version of the same. Now I know better