Skip to main content

为分支配置远程存储库

设置一个指向 Git 中的上游存储库的远程项,以同步分叉和原始存储库之间的更改。

  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. 添加一个名为 upstream 的新远程仓库,使其指向原始仓库。

    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)