DEV Community

Kavin Desi Valli
Kavin Desi Valli

Posted on • Edited on

How to update a forked repository to match with the origin repository on Github

When you want to contribute to open source, one of the most important things is understand, forking and branching.

Once you have updated some code and made a pull request, you might not do anything with your forks for a lot of time. So the next time you do something, you will have to update it. But how?

Add an upstream remote

We'll add a remote to our repository called upstream with the follow command:

git remote add upstream https://github.com/OriginalRepo/OriginalProject.git
Enter fullscreen mode Exit fullscreen mode

Make sure to use the link of the origin repository

Now you canverify by running

git remote -v
Enter fullscreen mode Exit fullscreen mode

Fetch branches and commits from upstream

Run the following command in order to fetch all the updated banches and commits from upstream

git fetch upstream
Enter fullscreen mode Exit fullscreen mode

Checkout your fork’s local master

git checkout master
Enter fullscreen mode Exit fullscreen mode

Merge changes from upstream/master into it

git merge upstream/master
Enter fullscreen mode Exit fullscreen mode

Push changes to update your fork master'

git push origin master
Enter fullscreen mode Exit fullscreen mode

Note that you might have a different base branch that master.

That's it.. Have fun!

I have started my own blog platform at https://blogs.livecode247.com
Have taken this content from there

Top comments (0)