Skip to main content

为分支配置远程存储库

必须在 Git 中配置指向上游存储库的远程存储库,才能将你在分支中所做的更改同步到原始存储库。 这也允许您将在原始仓库中所做的更改同步到复刻中。

Platform navigation

  1. 打开终端终端Git Bash

  2. 列出当前为复刻配置的远程仓库。

    $ git remote -v
    > origin  https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
    > origin  https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
    
  3. 指定将与分支同步的新远程上游存储库。

    git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
    
  4. 验证为复刻指定的新上游仓库。

    $ git remote -v
    > 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_REPOSITORY.git (fetch)
    > upstream  https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (push)