用git-flow来让git workflow自动化

/ git / 没有评论 / 107浏览

当分支过多时, 如何管理这些分支呢?这里介绍一种业界推荐的最佳实践——Git Flow

Git Flow分支模型

Git Flow工作流是经典模型,体现了工作流的经验和精髓。随着项目过程复杂化,会感受到这个工作流中深思熟虑和威力! Git Flow工作流没有用超出功能分支工作流的概念和命令,而是为不同的分支分配一个很明确的角色,并定义分支之间如何和什么时候进行交互

git-flow

Git Flow常用分支

master

也就是只能通过releasehotfix分支合并到master,并打tag

develop

也就是说:

feature

在平时开发功能时,从develop分支克隆出feature分支,本地开发(修复单元测试bug等),要上线时则合并到develop

release

hotfix

git-flow使用

如果我们手动通过git来操作这样的流程,操作起来可能不太方便,此时借助git-flow可以大大提高效率。

安装

Mac

$ brew install git-flow

Ubuntu

$ apt-get install git-flow

其他

Installation

初始化

$ git flow init
Initialized empty Git repository in ~/project/.git/
No branches exist yet. Base branches must be created now.
Branch name for production releases: [master]
Branch name for "next release" development: [develop]

How to name your supporting branch prefixes?
Feature branches? [feature/]
Release branches? [release/]
Hotfix branches? [hotfix/]
Support branches? [support/]
Version tag prefix? []

创建feature/release/hotfix分支

feature

To list/start/finish feature branches, use:

$ git flow feature
$ git flow feature start <name> [<base>]
$ git flow feature finish <name>

For feature branches, the arg must be a commit on develop.

To push/pull a feature branch to the remote repository, use:

$ git flow feature publish <name>
$ git flow feature pull <remote> <name>

要注意的是:

release

To list/start/finish release branches, use:

$ git flow release
$ git flow release start <name> [<base>]
$ git flow release finish <name>

For release branches, the arg must be a commit on develop.

hotfix

To list/start/finish hotfix branches, use:

$ git flow hotfix
$ git flow hotfix start <name> [<base>]
$ git flow hotfix finish <name>

For hotfix branches, the arg must be a commit on master.

参考