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

Chris Simpkins
Oct 10, 2017 · 2 min read
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

This step defines the upstream repository of your fork.

$ git remote add upstream [Upstream git URL]
$ git fetch upstream

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 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.

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

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.

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.


sweetmeat

Juicy lil’ bytes

 by the author.

Chris Simpkins

Written by

I make things and give them away for libre. Developer of Hack [https://github.com/source-foundry/Hack], Crunch [https://github.com/chrissimpkins/Crunch], ++

sweetmeat

sweetmeat

Juicy lil’ bytes

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade