Search This Blog

Github: fork a repository and sync the fork

  1. Fork a repository
    • Clone the repository:
      git clone https://github.com/ORIGINAL_OWNER/ORIGINAL_REPO.git
    • Add the original repository as upstream:
      git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPO.git
    • Check the status:
      git remote -v
      You will see:
      # origin    https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
      # origin    https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
      # upstream  https://github.com/ORIGINAL_OWNER/ORIGINAL_REPO.git (fetch)
      # upstream  https://github.com/ORIGINAL_OWNER/ORIGINAL_REPO.git (push)
      
  2. Sync the fork with upstream(original):
    • Fetch the branches and their respective commits from the upstream repository:
      git fetch upstream
    • Check out your fork's local master branch:
      git checkout master
    • Merge the changes from upstream/master into your local master branch. This brings your fork's master branch into sync with the upstream repository, without losing your local changes.
      git merge upstream/master
    • Push local repository:
      git push --tags

No comments:

Post a Comment