git使用,多分支合並代碼解決沖突,git刪除遠程分支,刪除遠程master默認分支方法
提交代碼流程:
1.先提交代碼到自己分支上
2.切換到devlop拉取代碼合並到當前分支
3.合並后有變動的推送到自己分支
3.到web上 https://gitlab.xxx.com/mobile/exchange 上選擇自己的分支,
點擊 Create Merge Requests ,選擇合並到devlop分支,Description填寫修改內容,提交。
New Merge Request -->默認到master的,點右上角Change branches-->Target branch 選擇devlop,點擊Compare branches and continue按鈕,
-->Description填寫修改內容-->點擊Submit merge request-->Merge(如果按鈕是灰色的會提示There are merge conflicts有合並沖突,需要解決沖突才能合並)
------------------
Introduction to GitLab Flow | GitLab
https://docs.gitlab.com/ee/workflow/gitlab_flow.html
------------------
Check out, review, and merge locally
Step 1. Fetch and check out the branch for this merge request
git fetch origin
git checkout -b devlop origin/devlop
Step 2. Review the changes locally
Step 3. Merge the branch and fix any conflicts that come up
git fetch origin
git checkout origin/qa
git merge --no-ff devlop
Step 4. Push the result of the merge to GitLab
git push origin qa
Tip: You can also checkout merge requests locally by following these guidelines.
--------------------
git刪除遠程分支
先查看遠程分支
git branch -r
使用下面兩條命令來刪除遠程分支
git branch -r -d origin/branch-name
git push origin :branch-name
在gitlab和github中可以在 project setting中更改 default branch
默認不一定非得是master, 也可以是其他, 比如新建分支temp, 把temp分支設置為 默認分支, 也就是主分支吧 , 不過按照約定俗稱的說法, 還是以master作為默認的主分支。
git刪除master分支后重建
每次誤操作后,都會引起當前分支低於遠程的master分支,然后導致無法完成git push origin master:master。
如果用:
git branch -D master;//刪除本地master分支
git push origin :master;//刪除遠程master分支
會發現刪除不了,因為在本地您處在master分支,在遠程master為默認分支。
解決之道:
1.先建立自己的分支。
git branch temp;
git push origin temp:temp;//將temp分支提交到遠程分支上。
2.在github上將master分支設置成不是default的分支,這里就要選擇temp分支了,因為只有兩個分支。
github操作,點擊后面的settings,選擇不是master的分支為默認。
3.再使用刪除:
git branch -D master;//刪除本地master分支
git push origin :master;//刪除遠程master分支
這樣就完成刪除了。
4.如果你還想在將master分支做為默認的分支,再建一個叫master的分支,然后類似操作(將內容提交到master分支上,push到遠程的github上,進入settings中設置master為默認的分支即可。)