git branch 使用時容易產生的問題
Remote
remote 開新 branch (ex. gitlab 從master開branchA)
Local
- git pull
此時會有master和branchA
- git branch -a
可以看到所有branch,不過除了master以外,應該其他目前都還是origin(也就是remote)
當我們想要進行修改的時候,應該先切換到目標的”local” branch,那因為剛pull下來只會有origin(也就是remote),所以可以先建立一個同名的loacal branch
若執意使用remote branch就會出現下列錯誤
|
|
- git checkout branchA
這邊git偵測沒有branchA就會自動建一條branch
|
|
接下來就修改需要的程式
- git add
- git commit
- git push
此時就會在branchA加上新的commit
好習慣
git merge (master to branchA)
建議每天都要將master merge回branchA,可以預防最後要將branchA merge回master時差異過大
- git pull
- git merge (master to branchA)
- git push
git merge (branchA to master)
若最後feature、bug開發完成,要把功能加回到master
- git push
- 到remote merge branchA to master
gitlab 發起新的 MR (Merge Request)
傳送給有權限的Assignee進行合併 - git pull (remote merge的紀錄local就會看到了)
MR (Merge Request) V.S. PR (Pull Request)
https://stackoverflow.com/a/29951658
基本上不用想太多
Gitlab 的 MR == Github 的 PR