Integrate a github fork's remote changes

Integrate a github fork's remote changes
Page content

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.


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.


Before you start the process, cd into your fork’s repository directory and run the following:

NOTE: fill in the blanks for


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 "${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.

Andreas Fuhrich avatar
About Andreas Fuhrich
I’m a professional software developer and tech enthusiast from Germany. On this website I share my personal notes and side project details. If you like it, you could support me on github - if not, feel free to file an issue :-)