Git Flow QuickStart

Introduction

Git Flow重点解决的是由于源代码在开发过程中的各种冲突导致开发活动混乱的问题。因此,Git flow可以很好的于各种现有开发模型相结合使用。

Git Flow模型中定义了主分支和辅助分支两类分支。其中主分支用于组织与软件开发、部署相关的活动;辅助分支组织为了解决特定的问题而进行的各种开发活动。

分支类型说明:

  • feature: 用于日常的功能开发,一般一个功能分支代表一个功能,一般一个功能分支代表一个功能。

    继承分支:develop,合并分支:develop,命名规则:任何名字除了master, develop, release-, hotfix-

  • release:当需要发布新版本时使用,主要用于测试。可在此分支上直接开发功能,修复bug,但务必同时合并到develop和master。

    继承分支:develop,合并分支:develop master,命名规则:release-*

  • hotfix:用于修复线上的bug,务必同时合并到develop和master。

    继承分支:master,合并分支:develop master,命名规则:hotfix-*


Git Flow Tools

Feature Branch

  1. 创建 feature 分支

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    git flow feature start login

    #### output #####
    Switched to a new branch 'feature/login'

    Summary of actions:
    - A new branch 'feature/login' was created, based on 'develop'
    - You are now on branch 'feature/login'

    Now, start committing on your feature. When done, use:

    git flow feature finish login
  2. 完成 feature 分支

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    git flow feature finish login

    #### output #####
    Switched to branch 'develop'
    Updating d2df03b..85d1933
    Fast-forward
    login.java | 0
    1 file changed, 0 insertions(+), 0 deletions(-)
    create mode 100644 login.java
    Deleted branch feature/login (was 85d1933).

    Summary of actions:
    - The feature branch 'feature/login' was merged into 'develop'
    - Feature branch 'feature/login' has been removed
    - You are now on branch 'develop'

此时,本地feature/login已经被删除,同时代码合并到了本地的develop分支。

如果想在github上保留feature/login,则需要手动push该分支。

Release Branch

  1. 创建 release 分支

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    git flow release start 1.13.1

    #### output #####
    Switched to a new branch 'release/1.13.1'

    Summary of actions:
    - A new branch 'release/1.13.1' was created, based on 'develop'
    - You are now on branch 'release/1.13.1'

    Follow-up actions:
    - Bump the version number now!
    - Start committing last-minute fixes in preparing your release
    - When done, run:

    git flow release finish '1.13.1'
  2. 完成 release 分支

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    git flow release finish '1.13.1'

    #### output #####
    Deleted branch release/1.13.1 (was 85d1933).

    Summary of actions:
    - Latest objects have been fetched from 'origin'
    - Release branch has been merged into 'master'
    - The release was tagged '1.13.1'
    - Release branch has been back-merged into 'develop'
    - Release branch 'release/1.13.1' has been deleted

完成release 1.13.1后,本地release 1.13.1会被删除 ,release代码会自动合并到本地 master 分支。

如果想在github上保留release 1.13.1,则需要手动push该分支。

  1. Push Tag
1
2
3
git push origin 1.13.1
## or
git push --tags

Hotfix Branch

1
2
3
4
5
# 创建hotfix分支
git flow hotfix start <name>

# 提交hotfix分支
git flow hotfix finish <name>

和release分支一样,提交时也会自动打上tag。


Reference

http://www.ruanyifeng.com/blog/2015/12/git-workflow.html
https://juejin.im/post/5c3e9b6df265da616c65d685