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

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay