iT邦幫忙

1

GitLab-更新Fork出來的專案

czw745 2019-02-25 16:46:2911466 瀏覽

在 GitLab 的介面上,可以透過Fork的功能,把別人的專案建立一個 fork 到自己的帳號底下,
例如原始專案的網址是 http://gitlab/userA/project.git
Fork出來的專案網址會是 http://gitlab/userB/project.git
不過原始專案仍然會繼續更新,而自己Fork下來的專案則會停在執行Fork當時的狀況。

1.git clone Fork出來的專案路徑

$ git clone http://gitlab/userB/project.git

2.git remote 操作前後先看狀態

$ git remote -v

預設應該只會有 origin 這個 remote:

origin http://gitlab/userB/project.git (fetch)
origin http://gitlab/userB/project.git (push)

3.git remote add 新增upstreamupstream 是 remote name,可以自己取名,不要重複就好

$ git remote add upstream http://gitlab/userA/project.git
$ git remote -v

再看一次現有的remote應該會發現多了兩組upstream(fetch & push):

origin http://gitlab/userB/project.git (fetch)
origin http://gitlab/userB/project.git (push)
upstream http://gitlab/userA/project.git (fetch)
upstream http://gitlab/userA/project.git (push)

有了原始專案的來源後我們就可以開始做更新了

4.切換回本地的master

$ git checkout master

5.接著把upstreammaster更新給拉進來

$ git pull upstream master

6.切換到開發用的分支rebase自己的master

$ git checkout branch_name
$ git rebase master

7.如果自己的mastercommit,也可以用rebase來避免不必要的merge操作

$ git checkout master
$ git pull --rebase upstream master

8.如果沒有發生衝突的話這樣應該就完成了本地的更新,再把更新後的 branch push 出去就行了

$ git push origin master

這時再回去看看自己的專案頁面,應該會發現已經同步到最新的狀態了!

PS.修改remote名稱

git remote rename {oldName} {newName}

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言