Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jacob-faber/90cacc388d55ff7125f3c8ccbf7ff569 to your computer and use it in GitHub Desktop.
Save jacob-faber/90cacc388d55ff7125f3c8ccbf7ff569 to your computer and use it in GitHub Desktop.
How to move to a fork after cloning

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.

To follow GitHub flow you should really have created a fork initially as a public representation of the forked repository and the clone that instead. My understanding is that the typical setup would have your local repository pointing to your fork as origin and the original forked repository as upstream so that you can use these keywords in other git commands.

  1. Clone some repo (you've probably already done this step)

  2. Fork their repo on Github

  3. In your local, rename your origin remote to upstream

    git remote rename origin upstream
  4. Add a new origin

    git remote add origin [email protected]
  5. Fetch from new origin

    git fetch origin
  6. Set origin master

    git branch --set-upstream master origin/master

    git branch --set-upstream-to origin/master master
  7. Push to fork (origin should be able to omitted given step 4)

    git push origin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment