DEV Community

Varun Barad
Varun Barad

Posted on • Originally published at varunbarad.com on

Sync git fork with upstream

It is a common situation when we fork a project on Github and after some time we want to update our fork with the changes that have been integrated into the source project from where we forked. This is a simple guide on how to do that.

Conditions:

  • We have the remote of source project added to our local git repo.
  • The name of the source project remote is upstream.
  • We are syncing changes from upstream/master to our local master branch.

Below are the steps I found on Github’s guide.

  1. Commit/Stash all your local changes.
  2. Checkout your local master branch if not already there. git checkout master
  3. Fetch (not pull) changes from upstream. git fetch upstream
  4. Merge changes from upstream/master to local master. git merge upstream/master
  5. Resolve merge-conflicts, if any.

And you are done. Your local master branch is now updated with changes from upstream/master.

Source: Github guide

Tip: Syncing like this will only update your local master. You will still need to push those synced changes to your Github repo if you want to update that too.

This was just a quick tip that I needed quite a lot recently and every time I had to go and search for that guide. So I wrote this to solidify the concepts in my mind. If you have any more such tips I would love to hear about them at this @varun_barad.

Top comments (0)