Update With Original Repo After Forking on GitHub

Way one

  1. open your local git repo

cd repo
  1. check your remote repo

git remote -v
origin  https://github.com/a/repo.git (fetch)
origin  https://github.com/a/repo.git (push)
  1. set upstream repo

git remote add upstream https://github.com/b/original-repo.git
  1. check your remote repo again

git remote -v
origin  https://github.com/a/repo.git (fetch)
origin  https://github.com/a/repo.git (push)
upstream https://github.com/b/original-repo.git (fetch)
upstream https://github.com/b/original-repo.git (push)
  1. execute git status to check whether there are uncommitted changes locally, if yes, push the commits to GitHub. Then execute git status again to confirm there are no uncommited changes locally.

git status
  1. fetch update from original repo

git fetch upstream
  1. switch to default branch main

git checkout main
  1. merge original main branch

git merge upstream/main
  1. push changes to your own forked repo

git push origin main

Way Two

Use GitHub’s Fetch upstream.

Last Way

  1. delete your forked repo

  2. fork again


ref:

Github 进行 fork 后如何与原仓库同步:重新 fork 很省事,但不如反复练习版本合并 https://github.com/selfteaching/the-craft-of-selfteaching/issues/67