If you are like me you find yourself cloning a repo, making some proposed changes and then deciding to later contributing back using the GitHub Flow convention. Below is a set of instructions I've developed for myself on how to deal with this scenario and an explanation of why it matters based on jagregory's gist.
Proper GitHub flow is this:
- upstream = the original (forked) repo
- origin = my fork
Current:
git remote -v
origin https://github.com/...some-repo (fetch)
origin https://github.com/...some-repo (push)
Should be:
git remote -v
origin https://github.com/...my-repo (fetch)
origin https://github.com/...my-repo (push)
upstream https://github.com/...some-repo (fetch)
upstream https://github.com/...some-repo (push)
-
Clone some repo (have already done this, instead of the forking first)
git clone [email protected] -
Fork their repo on GitHub (use the big green button)
-
In your local, rename your origin remote to upstream (ie. set the original repo as upstream)
git remote rename origin upstream -
Set your newly forked repo on GitHub as the new origin
git remote add origin [email protected] -
Set the tracking reference to your forked repo
git push -u origin master # same git push --set-upstream origin master
We can also move our changes to a branch
-
Create new branch
git checkout -b my-branch -
Push our branch to our repo
git push -u origin my-branch -
Reset our master branch to the original repo's master (which is now our UPSTREAM)
git checkout master git reset --hard upstream/master
https://gist.github.com/jpierson/b6c0815e9dd7078f6b8cc3cb9076ddf4