Gitlab管理之六–Gitlab分支管理

1. 切换到项目位置。
2. 建立一个项目的一新分支。
mike@win10-001 MINGW64 ~/cookbook/cookbook (master)
$ git branch first-branch
3. 切换到新建的分支下。
mike@win10-001 MINGW64 ~/cookbook/cookbook (master)
$ git checkout first-branch
Switched to branch 'first-branch'

mike@win10-001 MINGW64 ~/cookbook/cookbook (first-branch)
4. 第2步和第3步能够合并成一步。
mike@win10-001 MINGW64 ~/cookbook/cookbook (first-branch)
$ git checkout -b first-branch
5. 改变文件的内容。
mike@win10-001 MINGW64 ~/cookbook/cookbook (first-branch)
$ echo "Change" >> README.md
6. 提交这个改变
$ git commit -a -m 'Readme changed'
warning: LF will be replaced by CRLF in README.md.
The file will have its original line endings in your working directory.
[first-branch dc7b6d5] Readme changed
  1 file changed, 1 insertion(+)
7. 推送分支到gitlab服务器
mike@win10-001 MINGW64 ~/cookbook/cookbook (first-branch)
$ git push -u origin first-branch
Counting objects: 3, done.
Writing objects: 100% (3/3), 262 bytes | 131.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote:
remote: To create a merge request for first-branch, visit:
remote:   http://gitlab.aishangwei.net/root/cookbook/merge_requests/new?merge_request%5Bsource_branch%5D=first-branch
remote:
To gitlab.aishangwei.net:root/cookbook.git
  * [new branch]      first-branch -> first-branch
Branch 'first-branch' set up to track remote branch 'first-branch' from 'origin'.
8. 在Gitlab服务器查看咱们推送的分支

这里写图片描述

9. 从如下图能够看到建立的分支first-branch和master分支。

这里写图片描述

10. 切换到master分支。
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
11. 合并first-branch分支到master分支。
$ git merge first-branch –no-ff

这里写图片描述

12. 从第11步输出的信息能够看到,给咱们一个机会去改变提交的信息。在咱们保存和关闭编辑器的时候,这个分支将会合并,具体信息以下.
mike@win10-001 MINGW64 ~/cookbook/cookbook (master)
$ git merge first-branch --no-ff
Merge made by the 'recursive' strategy.
  README.md | 1 +
  1 file changed, 1 insertion(+)
13. 推送改变到Gitlab上的master.
mike@win10-001 MINGW64 ~/cookbook/cookbook (master)
$  git push origin master
Counting objects: 1, done.
Writing objects: 100% (1/1), 223 bytes | 223.00 KiB/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To gitlab.aishangwei.net:root/cookbook.git
    53ec2ca..5e1ebdd  master –> master
14. 删除所建立的分支。
mike@win10-001 MINGW64 ~/cookbook/cookbook (master)
$ git push origin --delete first-branch
To gitlab.aishangwei.net:root/cookbook.git
  - [deleted]         first-branch
15. 在gitlab服务器上查看信息以下。

这里写图片描述