DEV Community

Serhat Teker
Serhat Teker

Posted on • Originally published at tech.serhatteker.com on

Sync a Forked Repo

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:
  $ git remote add upstream https://github.com/User/original-repo.git
Enter fullscreen mode Exit fullscreen mode

or use SSH

  $ git remote add upstream git@github.com:User/original-repo.git
Enter fullscreen mode Exit fullscreen mode
  1. Fetch all branches of remote upstream:
  $ git fetch upstream
Enter fullscreen mode Exit fullscreen mode
  1. Rewrite your master with upstream’s master using git rebase:
  $ git rebase upstream/master
Enter fullscreen mode Exit fullscreen mode
  1. Push your updates to master.
  $ git push origin master
Enter fullscreen mode Exit fullscreen mode

You may need to force the push with:

  $ git push origin master --force
Enter fullscreen mode Exit fullscreen mode

All done!

Top comments (0)