Question

How to Keep Your Forked GitHub Repository up to Date?

Posted October 1, 2020 341 views
Linux BasicsGitLinux CommandsOpen Source

It is quite normal that, once you fork a repository that you want to contribute to on GitHub, after some time your fork will get quite behind the original repository.

Here are the steps that you need to follow in order to get the newest changes from the original repository pulled into your fork!

1 comment

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
2 answers

As an example, I will use my fork of the LaraSail project.

As of the time being, it is 9 commits behind. In order to get started, you need to do is to clone your fork. You can do that by going to GitHub and clicking on the Clone button:

How to sync fork repository GitHub

Once you’ve copied the URL, go to your command line and run the following command:

  • git clone git@github.com:bobbyiliev/larasail.git

Note: Make sure to change the link so that it matches your forked repository

Once you’ve cloned the repository, cd into the directory:

  • cd larasail

Then add the original repository to your fork as an upstream:

  • git remote add upstream git@github.com:thedevdojo/larasail.git

Note: change the details to match the original repository

After that, fetch the latest changes from the original repository:

  • git fetch upstream

The next thing that you need to do is to pull the latest changes in order to get your fork up to date:

  • git pull upstream main

This could be considered as an optional step, but the last thing that you need to do is to push those changes to your fork on GitHub:

  • git push origin main

Note: make sure to change main with the name of the branch that you want to sync with.

After that, if you go to your fork in GitHub, you will see a message saying This branch is even with the_origin_repo_name:main.

I hope that this helps!
Regards,
Bobby

Hi
For keeping a forked repository up to date: you just need to go to the location of the repository in your local disk and then run the command:

$ git pull <URL of the repo you forked>

It will not only bring changes to your local disk but also merge it inside it.
I hope it helps.

Regards
Neha Singh

Submit an Answer