I recently have been trying to contrbute more to open source and wanted to have as similar git workflows to my personal and proffesional projects. To contribute to a Github Project, you would have to fork the repo, create and push branch with your changes, submit the PR. A few days later, if you want to make a new contribution you would then create a new branch again.

In a fork, pulling from master doesn’t pull from the the original repo. It pulls from your forked master which shouldn’t change. This becomes a mental burden to remember to pull from the regulary pull the originaly repo and merge to your master.

Setting up

Fork Repo

Go to github and fork the the desired repository. This creates a clone under your user.

Clone forked Repos

Clone the repo locally

git clone [email protected]/forked/example

Set upstream remote

Create a new remote pointing to the original repository. For the code snippet below, we named the orginal remote to be named upstream.

git remote add upstream
git fetch remote

Set master of local to track upstream

Edit you .git/config so that the master branch follows the remote upstream

[branch "master"]
	remote = upstream # This was orignally origin
	merge = refs/heads/master

or run the following command

git branch master --set-upstream-to=upstream/master

“New” workflow

The end workflow would be identical to my current workflow for my other projects.

  1. Checkout master
  2. Pull from origin
  3. Branch out

or the equivalent commands to be

git checkout master
git pull
git checkout -B example-branch


Alternatively you can just set up the upstream remote, skip setting the remote of master, and just pull from remote.

The worflow for that would be

git chekout master
git pull remote master
git checkout -B example-branch