Skip to main content

为分支配置远程存储库

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

Platform navigation

  1. 打开终端终端Git Bash

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

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

    git remote add upstream https://HOSTNAME/ORIGINAL-OWNER/ORIGINAL-REPOSITORY.git
    
  4. 验证为复刻指定的新上游仓库。

    $ git remote -v
    > origin    https://HOSTNAME/YOUR-USERNAME/YOUR-FORK.git (fetch)
    > origin    https://HOSTNAME/YOUR-USERNAME/YOUR-FORK.git (push)
    > upstream  https://HOSTNAME/ORIGINAL-OWNER/ORIGINAL-REPOSITORY.git (fetch)
    > upstream  https://HOSTNAME/ORIGINAL-OWNER/ORIGINAL-REPOSITORY.git (push)