Update a GitHub Fork

How to update a GitHub forked repository with changes from the original repository.

·1 min read

GitHub forked repositories can be updated from GitHub UI or terminal.

To update from GitHub UI, you can create a "Pull Request" from the original repository to yours.

For updating using the terminal, add the original repo as a remote upstream to sync from.

Note: GitHub changed the default branch name from master to main in 2020. The commands below use main, but older repositories may still use master. Check your repo's default branch with git branch -a.

bash
# check that there is no remote upstream repo and add one
git remote -v
git remote add upstream https://github.com/OriginalOrgOrUser/OriginalRepo.git

# verify that upstream has been added and fetch branches and commits from upstream
git remote -v
git fetch upstream

# checkout fork's main branch and do a merge of upstream/main into it
git checkout main
git merge upstream/main

# push the changes to update your fork
git push

Keep reading