Update a fork of a repository to keep it up-to-date with the upstream repository.

  1. 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
    
  2. Fetch all branches of remote upstream:

    $ git fetch upstream
    
  3. Check out to your fork’s local master branch:

    $ git checkout master
    
  4. Rewrite your master with upstream’s master using git rebase:

    $ git merge upstream/master
    
  5. 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