以下例子以 github中 IBM/Drain3 為例
fork目標倉庫並將fork完的倉庫clone到本地
$ git clone https://github.com/ieven/Drain3.git
Cloning into 'Drain3'...
remote: Enumerating objects: 231, done.
remote: Counting objects: 100% (231/231), done.
remote: Compressing objects: 100% (143/143), done.
remote: Total 565 (delta 132), reused 162 (delta 78), pack-reused 334
Receiving objects: 100% (565/565), 115.33 KiB | 299.00 KiB/s, done.
Resolving deltas: 100% (331/331), done.
複製程式碼
$ cd Drain3/
複製程式碼
執行命令 git remote -v 檢視你的遠端倉庫的路徑
iEven@DESKTOP-OG5S6BE MINGW64 /d/try/Drain3 (master)
$ git remote -v
origin https://github.com/ieven/Drain3.git (fetch)
origin https://github.com/ieven/Drain3.git (push)
複製程式碼
如果只有上面2行,說明你未設定upstream。如果存在則跳過下面建立upstream步驟。
建立upstream
iEven@DESKTOP-OG5S6BE MINGW64 /d/try/Drain3 (master)
$ git remote add upstreamhttps://github.com/IBM/Drain3.git
iEven@DESKTOP-OG5S6BE MINGW64 /d/try/Drain3 (master)
$ git remote -v
origin https://github.com/ieven/Drain3.git (fetch)
origin https://github.com/ieven/Drain3.git (push)
upstream https://github.com/IBM/Drain3.git (fetch)
upstream https://github.com/IBM/Drain3.git (push)
複製程式碼
所以再次執行命令git remote -v
如果出現上圖說明成功。
獲取upstream的更新
執行命令git fetch upstream
抓取 Drain3 原倉庫的更新。
iEven@DESKTOP-OG5S6BE MINGW64 /d/try/Drain3 (master)
$ git fetch upstream
自動會同步原倉庫更新
複製程式碼
合併到本地倉庫的master分支
iEven@DESKTOP-OG5S6BE MINGW64 /d/try/Drain3 (master)
$ git checkout master
如果在master分支的可以省略
iEven@DESKTOP-OG5S6BE MINGW64 /d/try/Drain3 (master)
$ git merge upstream/master
會顯示合併過程
複製程式碼
push到自己的遠端倉庫
執行命令git push
把本地倉庫向github倉庫(你fork到自己名下的倉庫)推送修改。注意git push後面沒有其他引數。
iEven@DESKTOP-OG5S6BE MINGW64 /d/try/Drain3 (master)
$ git push
輸入你的賬號密碼進行push
複製程式碼
至此你fork的倉庫就更新完成了