Sync a Forked Repository with Upstream
Update a fork of a repository to keep it up-to-date with the upstream repository.
Add the remote (original repo you forked) and call it
upstream, if you haven’t already done so:$ git remote add upstream https://github.com/User/original-repo.gitor use
SSH:$ git remote add upstream [email protected]:User/original-repo.gitFetch all branches of remote
upstream:$ git fetch upstreamCheck out to your fork’s local
masterbranch:$ git checkout masterRewrite your master with
upstream’smasterusing git rebase:$ git merge upstream/masterPush your updates to
master:$ git push origin masterYou may need to
forcethe push:$ git push origin master --force
All done!
Info
Edited: 2020-06-18 15:10:23 UTC
In previous version of this post, on step 3, I was using rebase.
$ git rebase upstream/master
Since merge would be a better approach —instead of ’re-writing’ the history keeping all the history is better, I updated the post with merge technique.
For more info you can look at : Why you should stop using Git rebase
Subscribe
Read Related