Integrate a github fork's remote changes
Creating a fork on github is the default way of submitting pull requests or perform off the shelf changes. If you would like to re-integrate the updates from an upstream repository, this is sometimes a bit tricky. Here is how to do this.
Introduction
Github forks are basically cloning a repository into your own space. Most of the time, this is required to do small changes and submit pull requests. However, sometimes you might want to do some changes, that should not be submitted into the main repository - but still use the upstream changes to be on track.
Re-integrate
Before you start the process, cd
into your fork’s repository directory and run the following:
NOTE: fill in the blanks for
ORG_REPO_USERNAME
ORG_REPO_NAME
MAIN_BRANCH
or change the commands manually
ORG_REPO_USERNAME="" # e.g. sandreas
ORG_REPO_NAME="" # e.g. m4b-tool
MAIN_BRANCH="" # e.g. main
# add the original repository as remote with name "upstream"
git remote add upstream "https://github.com/${ORG_REPO_USERNAME}/${ORG_REPO_NAME}.git"
# fetch the "upstream" repository
git fetch upstream
# rewrite your master with upstreams master via git rebase
# NOTE: This may fail with merge conflicts
git rebase upstream/${MAIN_BRANCH}
# Usually, everything goes well here, but sometimes you will have a merge conflict.
# If so, you have to manually resolve merge conflicts and then:
# git rebase --continue
# push YOUR updates to master - maybe you need a `--force-with-lease`
git push origin ${MAIN_BRANCH} --force-with-lease
Now your fork should be up-to-date with the upstream changes.