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服务器查看我们推送的分支

Gitlab管理之六–Gitlab分支管理_第1张图片

9. 从以下图可以看到创建的分支first-branch和master分支。

Gitlab管理之六–Gitlab分支管理_第2张图片

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

Gitlab管理之六–Gitlab分支管理_第3张图片

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服务器上查看信息如下。

Gitlab管理之六–Gitlab分支管理_第4张图片

你可能感兴趣的:(Gitlab)