Skip to content

Instantly share code, notes, and snippets.

@acannistra
Last active September 11, 2018 21:28
Show Gist options
  • Save acannistra/57a7f0c7e18c44811dfe47f8a14cb020 to your computer and use it in GitHub Desktop.
Save acannistra/57a7f0c7e18c44811dfe47f8a14cb020 to your computer and use it in GitHub Desktop.

Need to sync a fork with the main repo?

Let's say you've forked a repository and cloned it to your local machine. Your Favorite Collaborator has added a pull request and had it approved by the repository maintainer; you'd now like that code in your personal fork. Here's how.

Make sure you've cded into your fork of the repository on your computer.

1. set upstream

You need to tell the fork where its original version lives. This is called "setting the upstream":

git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git

2. fetch upstream

Next, you'll tell your local copy of git to grab the latest version of the original. This does not yet incorporate the code to your local copy. It just downloads it.

git fetch upstream

3. merge

Finally, tell git to merge the master branch of the latest version of the original (which you just downloaded) to your current branch.

git merge upstream/master

(more info here: https://help.github.com/articles/configuring-a-remote-for-a-fork/ and here: https://help.github.com/articles/syncing-a-fork/)

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