How to sync a Master branch from a Fork

How to sync a Master branch from a Fork

Written by Dev Dojo on Jul 28th, 2017 Views Report Post

Need to sync your forked branch with the original master branch. Read on to learn how to do this.

Let's say you forked a repo 2 weeks back and you made some changes and even a pull request. Now, you're getting back into your forked branch and your forked branch is not synced with the original repo master branch.

Simple enough, you can do the following:

$ git fetch upstream

Wu Oh! Did you get an error? Something like:

fatal: 'upstream' does not appear to be a git repository

No worries! That means that you need to tell your repo where to fetch this remote upstream. You can do this with the following:

$ git remote add upstream https://github.com/the-control-group/voyager

make sure to add the original github repo URL for your project

Now, you can confirm that you have the upstream repo specified by running:

$ git remote -v
origin      https://github.com/tnylea/voyager.git (fetch)
origin      https://github.com/tnylea/voyager.git (push)
upstream    https://github.com/the-control-group/voyager (fetch)
upstream    https://github.com/the-control-group/voyager (push)

You should only need to add the upstream once from here on out you will be able to sync your forked branch by doing the following:

$ git fetch upstream

Make sure to checkout master branch

$ git checkout master

And lastly merge the remote upstream (or the original repo)

git merge upstream/master

And BOOM! your forked repo is now synced with the latest master branch ;)

Comments (0)