This is something I often do but rarely remember the steps for. This post is intended to serve as a reminder for me and anyone else having the same question: how to add an upstream remote git repository.

Start by forking the repository you are contributing to and cloning that repository to your local file system. In this example, we will use the Elasticsearch repository and assume you have cloned it locally.

git clone https://github.com/soofaloofa/elasticsearch.git

Now, we can add the upstream remote using the following command.

git remote add upstream https://github.com/elastic/elasticsearch.git

Now that you have a remote repository configured, you can fetch all branches:

git fetch upstream

From here, you can checkout a branch to base your work off of. In many cases, this means rebasing your changes onto the upstream branch:

git rebase upstream/master

This is basic git stuff, but since I always end up searching for it, I thought it would be useful to write it down for future reference. So, here it is!