如何将分支与原始GitHub项目同步?

17

我创建了某个GitHub项目的分支。然后我创建了新的分支并在其中打了一个补丁。我向作者发送了拉取请求(pull request),他应用了我的补丁并稍后添加了一些提交(commits)。现在我该如何将我的GitHub分支与原始项目同步? 我需要删除GitHub上的分支并每次为每个补丁创建新的分支吗?


可能是如何更新GitHub分叉存储库?的重复问题。 - Ciro Santilli OurBigBook.com
1个回答

35

你不需要再次进行 refork。只需添加一个远程仓库(比如叫做upstream),然后运行fetch upstream即可更新你的克隆仓库。

$ git remote add upstream <original-repo-url>
$ git fetch upstream                 # update local with upstream

$ git diff HEAD..upstream/master     # see diffs between local and upstream/master (if there is no diff then both are in sync)

$ git pull upstream master           # pull upstream's master into local branch
$ git push origin HEAD               # push to your forked repo's remote branch

获取原始仓库的新 标签(tags):

$ git fetch upstream --tags    # get original repo's tags
$ git push origin --tags       # push to forked repo

这会同步原始项目中的所有新标签吗? - eastwater
请执行以下命令以同步标签:git fetch upstream --tags; git push origin --tags - Sajib Khan
谢谢。只用一个标签怎么样? - eastwater
如果您只想推送一个标签,请尝试以下命令:$ git push origin refs/tags/<tag-name> - Sajib Khan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接