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"