Skip to content

Instantly share code, notes, and snippets.

@defunctzombie
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save defunctzombie/8873364 to your computer and use it in GitHub Desktop.
Save defunctzombie/8873364 to your computer and use it in GitHub Desktop.
working with upstream brances

Whenever you have a fork of a project which you intend to contribute, you will find it useful to stay up to date with the code from the upstream project you have cloned.

This can be easily accomplished by adding additional "remotes".

Using the engine.io-client repo as the base example.

Assuming you have forked the project on github and then cloned your fork locally.

cd engine.io-client

Add a new remote called upstream to our list of remotes. When you clone a repo, the origin remote is added for you automatically and points to the location you cloned from. By adding a new remote, we are able to fetch commits and branches from other locations.

git remote add upstream https://github.com/LearnBoost/engine.io-client.git

Before our local git database knowns about the commits in the new remote we need to fetch them.

git fetch upstream

We now want to make a new local branch that will reflect the latest changes from the upstream engine.io-client master branch. We will call this new branch upstream

git checkout -b upstream -t upstream/master

You will see a message about checking out and tracking a new remote branch. This is correct. You can see what branch you are on with git branch or see all branches with git branch -a

If you want to update your upstream branch to the latest changes; first change to upstream if you are not already on it.

git checkout upstream

Now get the latest changes.

git pull

When you are ready to start working on some new feature and want to use upstream as a starting point.

git checkout upstream && git checkout -b "name-of-new-branch"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment