How to update local repository from upstream

Lets say you are working locally with a fork of some repository.

To have your forked repository in sync you will need occasionally updated it from original repo. Usually you will do something like this:

#currently you are in local repo of your fork
git checkout master

#upstream in this context is the original repo you was forking from
git fetch upstream 

#bring all changes into local master
git merge upstream/master

Most of the time this works fine until you changed (usually accidentally) local master and forget to revert it. In this case merge will proceed and create an additional merge commit. Now your local master and upstream master are in not in sync.

The better approach will be using fast forward only option.

git merge upstream/master --ff-only

By doing so you are forcing merge to proceed only in fast-forward mode meaning that it will fail if the local master cannot be updated with upstream master smoothly.

Get the latest posts delivered right to your inbox.