Git 把碼雲上被fork項目源碼merge到fork出來的分支項目git
By:授客 QQ:1033553122github
被fork的項目有更新代碼,但願把更新的代碼merge到fork分支項目bash
一、clone fork分支項目到本地,併入切換當前分支爲目標分支。ssh
二、增長被fork項目源碼倉庫地址到你項目遠程分支列表中),並將該倉庫地址命名爲upstream(固然也能夠是其它),以下:fetch
git remote add upstream https://github.com/srcRepo.gitspa
其中 srcReop爲被fork項目blog
三、取回遠程主機被fork項目的所有更新rem
git fetch upstream源碼
固然,也能夠指定只取回目標分支it
git fetch upstream remoteTargeBranch
四、合併取回的目標分支(例中爲master)代碼到本地當前分支
git merge upstream/master
至此,完成了本地代碼的合併,接下來只須要push到fork項目的目標分支便可。
步驟3,步驟4也能夠直接使用pull命令替代,合併爲一個步驟,以下
git pull upstream master
(例中使用ssh訪問倉庫)
進入對應項目的 git bash後執行的如下命令
cassmall@DESKTOP-O45PJTA MINGW64 /e/PrivateReops/CassTestManage (V2.0)
$ git remote add upstream git@gitee.com:xxxx/CassTestManage.git
cassmall@DESKTOP-O45PJTA MINGW64 /e/PrivateReops/CassTestManage (V2.0)
$ git remote -v
origin git@gitee.com:laiy/CassTestManage.git (fetch)
origin git@gitee.com:laiy/CassTestManage.git (push)
upstream git@gitee.com:xxxx/CassTestManage.git (fetch)
upstream git@gitee.com:xxxx/CassTestManage.git (push)
cassmall@DESKTOP-O45PJTA MINGW64 /e/PrivateReops/CassTestManage (V2.0)
$ git pull upstream master
remote: Enumerating objects: 64, done.
remote: Counting objects: 100% (64/64), done.
remote: Compressing objects: 100% (63/63), done.
remote: Total 64 (delta 0), reused 58 (delta 0)
Unpacking objects: 100% (64/64), done.
From gitee.com3:xxxx/CassTestManage
* branch master -> FETCH_HEAD
* [new branch] master -> upstream/master
Merge made by the 'recursive' strategy.
mytest.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 mytest.txt
cassmall@DESKTOP-O45PJTA MINGW64 /e/PrivateReops/CassTestManage (V2.0)
$
第二次開始,能夠經過git客戶端界面進行代碼的合併操做,很是簡單,以下指定遠程主機和要pull的分支便可。