首先我们将原仓库添加为 upstream

1
git remote add upstream https://github.com/原作者/repo.git

添加完成后,运行 git remote -v 检查,应该有 origin (指向自己的仓库) 和 upstream (指向原仓库)

然后拉取原仓库的所有分支

1
git fetch upstream

在拉取完成之后,运行 git branch -r,应该可以看到希望同步的那个分支 upstream/feature-x

最后,把 upstream 的 feature-x 拉取成本地的 branch

1
git switch -c feature-x upstream/feature-x

这里的 -c 参数表示:新建 feature-x 分支.随即 switch 到这个新分支上

至此,本地仓库的 feature-x 分支就包含了 upstream/feature-x 全部内容.我们再将 feature-x 给推送到 GitHub 上:

1
git push origin feature-x