美文网首页前端开发那些事儿
GitHub 进行 Fork 后如何与原仓库同步

GitHub 进行 Fork 后如何与原仓库同步

作者: CHMAX | 来源:发表于2020-10-08 12:12 被阅读0次
  1. 检查当前远程仓库的路径。
$ git remote -v
origin  https://github.com/chenhui0212/hll-api-navigator.git (fetch)
origin  https://github.com/chenhui0212/hll-api-navigator.git (push)
  1. 添加原仓库。
$ git remote add upstream https://github.com/JetBrains/intellij-platform-plugin-template.git
  1. 再次查看远程仓库的路径。
$ git remote -v
origin  https://github.com/chenhui0212/hll-api-method-navigator.git (fetch)
origin  https://github.com/chenhui0212/hll-api-method-navigator.git (push)
upstream    https://github.com/JetBrains/intellij-platform-plugin-template.git (fetch)
upstream    https://github.com/JetBrains/intellij-platform-plugin-template.git (push)
  1. 拉取原仓库代码(更新亦可)。
$ git fetch upstream
warning: 没有共同的提交
remote: Enumerating objects: 55, done.
remote: Counting objects: 100% (55/55), done.
remote: Compressing objects: 100% (39/39), done.
remote: Total 814 (delta 26), reused 37 (delta 15), pack-reused 759
接收对象中: 100% (814/814), 822.41 KiB | 363.00 KiB/s, 完成.
处理 delta 中: 100% (427/427), 完成.
来自 https://github.com/JetBrains/intellij-platform-plugin-template
 * [新分支]          main       -> upstream/main
 * [新标签]          v0.0.2     -> v0.0.2
 ...
 * [新标签]          v0.3.4     -> v0.3.4
  1. 合并原仓库分支。
$ git merge upstream/main
fatal: 拒绝合并无关的历史
  1. 如果出现如上信息,可以添加 --allow-unrelated-histories 参数进行合并。
$ git merge --allow-unrelated-histories upstream/main
  1. 如果存在冲突,这里需要手动解决,最后推送合并之后的分支。
$ git push

相关文章

网友评论

    本文标题:GitHub 进行 Fork 后如何与原仓库同步

    本文链接:https://www.haomeiwen.com/subject/kegcpktx.html