til

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 Compare, set your forked repo left(base repo), set your original repo right(compare with).

Then create a merge for your forked repo, and merge it. exercise

Last Way

  1. delete your forked repo
  2. fork again

References