When you have forked the GitHub repository and applied some fixed which then sent PR and it got merged successfully to its upstream repository. After a while, another change was made by another contributor in upstream branch.
At this stage, your forked repository wouldn’t contain the code made on the upstream branch. To continue your contributions or work with the upstream repository you must have to keep up to date your fork repo.
Many times, After googling when they don’t get the right solution, they delete and re-create the fork which is not the right way at all. Initially, As a GitHub newbie, I also had no clue how to keep up to date my fork repo with the upstream master repository.
It can be done through just few line of command mentioned below.
I had forked GitHub repo MrRio/jsPDF to emgk/jsPDF and want to keep it up to date.
Once, you had forked the repo on GitHub clone it on your local machine and then add a remote that points to the upstream repository.
$ git clone firstname.lastname@example.org:emgk/jsPDF.git $ cd jsPDF $ git remote add upstream email@example.com:MrRio/jsPDF.git
Each time you want an update from the repository you can run these command:
$ git fetch upstream $ git rebase upstream/master
Using rebase will keep your branch cleaner history if you have local commits on the repo.
if you don’t want to rewrite the commit history then just replace the last command with
$ git fetch upstream $ git merge upstream/master
Simply push it so that all of the new changes can be updated.
$ git push origin master
Hope it helps, Thanks.