Skip to content

Instantly share code, notes, and snippets.

@emmahsax
Last active February 10, 2023 15:39
Show Gist options
  • Save emmahsax/a64ee7146e0e6ac3ebd36e12f9e1d35c to your computer and use it in GitHub Desktop.
Save emmahsax/a64ee7146e0e6ac3ebd36e12f9e1d35c to your computer and use it in GitHub Desktop.
How to merge forks back in with upstream

Merging Forks with Upstream

Check to see if there's changes in upstream that you need to make in your fork

Look for a message like this. If it says that your default branch is behind the upstream's default branch (usually master), it means there are updates:

image

If there are updates, then merge your local fork with upstream

Clone your fork to your local machine OR cd to it:

git clone https://github.com/[your-username]/[fork-repository].git # or [email protected]:[your-username]/[fork-repository].git
# OR
cd fork-repository/

See if there's an upstream remote or not.

git remote -v

If there is no upstream remote, then run the following. Else, skip this step.

git remote add upstream https://github.com/[original-owner]/[original-repository].git

Grab updates from the remote:

git fetch upstream

Get onto your fork's default branch (or create a new branch off of your fork's default branch for this merge specifically):

git checkout [default-branch]

Merge upstream to your fork's local branch:

git merge upstream/[upstream's-default-branch]

Make sure there's no merge conflicts. It can also be helpful to run the tests locally and test as much as possible locally, so you know if there’ll be any breaking changes. If the fork requires packages to be built, make sure to build changes the packages with the new changes before committing to the origin's default branch.

When you're ready, push to your fork's origin to finish updating

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