如何同步master的代码到fork分支代码

同步master的代码到fork分支代码,分三步(remote项目fetch到本地仓库、基于本地master重新创建一个branch、新的branch上commit&push):

1. 项目 fetch 到本地仓库,通过命令行的方式 merge

a. git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
b. git fetch upstream
c. git checkout master(master换成lzc_first_branch,是否可以直接切到lzc_first_branch分支?,从而跳过第二步)
d. git merge upstream/master(master换成lzc_first_branch,是否可以直接merge到lzc_first_branch分支?,从而跳过第二步)

2. 基于本地master重新创建一个branch

 git checkout -b lzc_second_branch master

或者

git checkout master

 git checkout -b lzc_second_branch

3. 基于该lzc_second_branch分支,提交到远程仓库

a.  git commit -a 'sync codes from upstream'

b. git push origin master(这个是push到fork之后的远程仓库)

那么,有没有办法,直接从remote项目同步到remote的fork分支呢??

参考:http://jinlong.github.io/2015/10/12/syncing-a-fork/

原文地址:https://www.cnblogs.com/liuzc/p/6714965.html