本文首发简书 http://www.jianshu.com/p/840ea273f25a
github上fork之后,原始分支有改动,该如何同步原始分支呢? 还是需要google下, 作为一个小技巧! 下面就以我的 google官方android-architecture为例说明。 习惯使用【Git Bash】方式,本文就以命令行操作!
操作之前,先看下 fork之后github的更新提示。
使用GitBash进入到项目目录,简单的方式是从文件管理器中,打开GitBash, 或者是Window CMD.
与上游仓库同步代码之前,必须配置 remote,指向上游仓库 本文为例, 上游原始仓库为: https://github.com/googlesamples/android-architecture.git
git remote add upstream https://github.com/googlesamples/android-architecture.git格式类似:
git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git使用如下命令查看下:git remote -v
$ git remote -v origin https://github.com/tancolo/android-architecture.git (fetch) origin https://github.com/tancolo/android-architecture.git (push) upstream https://github.com/googlesamples/android-architecture.git (fetch) upstream https://github.com/googlesamples/android-architecture.git (push)上部分是自己远程仓库,下部分是上游仓库地址!
我习惯是fork的项目,一般不在主分支修改,自己另建分支, 所以, 切换到本地master分支!
git checkout master结果如下图, 上游仓库涉及的分支比较多!
要是想更新其他分支,需要执行
1. git checkout 其他分支名 2. git merge upstream/其他分支名 3. git push origin 其他分支名http://jinlong.github.io/2015/10/12/syncing-a-fork/ https://www.zhihu.com/question/20393785
