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.git
or use
SSH
:$ git remote add upstream [email protected]:User/original-repo.git
Fetch all branches of remote
upstream
:$ git fetch upstream
Check out to your fork’s local
master
branch:$ git checkout master
Rewrite your master with
upstream
’smaster
using git rebase:$ git merge upstream/master
Push your updates to
master
:$ git push origin master
You may need to
force
the 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