When you fork a project on GitHub, changes to the original repository do not automatically sync with yours. This can lead to merge conflicts, or when you create a new branch for a PR not having the latest version. Updating your fork can be done with just a few commands.
Initial Setup
If you haven't already done so you will need to set the upstream url for your local environment.
Note: replace original-author with the username that you forked from, and repo-name with the repository name.
git remote add upstream https://github.com/original-author/repo-name
Updating Your Fork
Whenever you wish to update your fork, follow the steps below.
Note: replace master with the default branch name if required.
Switch to the main branch
git checkout master
Fetch changes from the original repo.
git fetch upstream
Merge changes into local environment.
git merge --ff-only upstream/master
Push changes into fork.
git push origin master
Updating Your Branch
If you started working in a new branch and then changes have come in that you would like to merge, follow the steps below.
Note: replace my-feature with your branch name, and master with the default branch name if required.
Switch to your branch.
git checkout my-feature
Rebase on to the main branch.
git rebase master
Resolve any conflicts if needed.
Push your updated branch.
git push --force origin my-feature