How to Keep a Downstream git Repository Current with Upstream Repository Changes

Chris Simpkins
sweetmeat
Published in
2 min readOct 10, 2017
photo by Igor Ovsyannykov https://unsplash.com/photos/srd-rZ5fcFw

This article demonstrates how to keep a downstream repository current with upstream repository changes as you perform work.

Problem

A downstream repository (aka a “fork”) maintainer commonly needs to stay current with upstream work. The following steps allow you to achieve this on the command line in a local git repository.

Steps

Add the Remote Upstream Repository

This step defines the upstream repository of your fork.

$ git remote add upstream [Upstream git URL]

Fetch the Upstream Branches

$ git fetch upstream

Merge Upstream Changes into your Downstream Repository

From your master branch, use the following merge command to merge the upstream master branch changes into your local source:

$ git merge upstream/master

Create a New Branch for Work

Create a branch off of the master branch that will include the new work. While working in the master branch, execute the following (with any appropriate branch name in quotes):

$ git checkout -b "feature-new-stuff"

Here, we defined the branch feature-new-stuff and will perform work there.

Perform Your Local Work

Follow the standard local repository workflow of file changes with git add + git commit steps for the files.

Push Changes to Your Downstream Remote Repository

When you are ready to push changes to your remote fork of the upstream repository, use the following:

$ git push origin feature-new-stuff

Your local and remote downstream repositories are now current with your local feature-new-stuff changes and this branch is current with the upstream repository changes as of the time of the merge step above.

Repeat

You can checkout your master branch and repeat the process above whenever you need to update your repository with the work that has occurred upstream since the last merge was performed.

--

--