Git-flow 工作流
https://github.com/petervanderdoes/gitflow-avh
http://jeffkreeftmeijer.com/2010/why-arent-you-using-git-flow/
http://danielkummer.github.io/git-flow-cheatsheet/
安装:
https://github.com/petervanderdoes/gitflow-avh/wiki/Installation
Git-flow 介绍:
https://jeffkreeftmeijer.com/git-flow/
Git-flow 相关指令:
- git flow init 初始化项目
- git flow feature start feature_name 创建功能分支
- git flow feature finish feature_name 完成功能分支
- git flow release start version 创建预发布分支
- git flow release finish version 完成预发布分支
- git flow hotfix start assets 创建快速修复分支
- git flow hotfix finish assets 完成快速修复分支
指令简介
git flow init
初始化 git-flow
默认:
Branch name for production releases: [master]
Branch name for "next release" development: [develop]
各个类型分支前缀:
How to name your supporting branch prefixes?
Feature branches? [feature/]
Bugfix branches? [bugfix/]
Release branches? [release/]
Hotfix branches? [hotfix/]
Support branches? [support/]
Version tag prefix? []
git flow feature start/finish/publish/pull feature_name
work on multiple features at the same time
start 解析:
1、基于 develop 分支创建一个新的分支 feature/authentication
2、切换至 feature/authentication 分支
$ git flow feature start authentication
Switched to a new branch 'feature/authentication'
Summary of actions:
- A new branch 'feature/authentication' was created, based on 'develop'
- You are now on branch 'feature/authentication'
Now, start committing on your feature. When done, use:
git flow feature finish authentication
finish 解析:
1、切换至 develop 分支
2、merge feature/authentication 分支
3、删除 feature/authentication 分支
$ git flow feature finish authentication
Switched to branch 'develop'
Updating 9060376..00bafe4
Fast-forward
authentication.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 authentication.txt
Deleted branch feature/authentication (was 00bafe4).
Summary of actions:
- The feature branch 'feature/authentication' was merged into 'develop'
- Feature branch 'feature/authentication' has been removed
- You are now on branch 'develop'
git flow release start/finish/publish/pull version
ready to deploy a new version to production
start 解析:
1、以 develop 为基础创建一个预发布版本分支 release/0.1.0
2、切换分支至 release/0.1.0
$ git flow release start 0.1.0
Switched to a new branch 'release/0.1.0'
Summary of actions:
- A new branch 'release/0.1.0' was created, based on 'develop'
- You are now on branch 'release/0.1.0'
Follow-up actions:
- Bump the version number now!
- Start committing last-minute fixes in preparing your release
- When done, run:
git flow release finish '0.1.0'
finish 解析:
1、切换分支至 master
2、合并 release/0.1.0 分支
3、为当前 master 打tag 0.1.0
4、将 release/0.1.0 合并到 develop
5、删除 release/0.1.0 分支
$ git flow release finish 0.1.0
Switched to branch 'master'
Merge made by the 'recursive' strategy.
authentication.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 authentication.txt
Deleted branch release/0.1.0 (was 1b26f7c).
Summary of actions:
- Latest objects have been fetched from 'origin'
- Release branch has been merged into 'master'
- The release was tagged '0.1.0'
- Release branch has been back-merged into 'develop'
- Release branch 'release/0.1.0' has been deleted
git flow hotfix start/finish/publish/pull assets
quickly fix any issues on production
start 解析:
1、以master 分支为基础创建一个 assets 分支
2、切换分支至 assets
$ git flow hotfix start assets
Switched to a new branch 'hotfix/assets'
Summary of actions:
- A new branch 'hotfix/assets' was created, based on 'master'
- You are now on branch 'hotfix/assets'
Follow-up actions:
- Bump the version number now!
- Start committing your hot fixes
- When done, run:
git flow hotfix finish 'assets'
finish 解析:
1、切换 master 分支
2、合并 assets 分支
3、打tag 0.1.1
4、合并 assets 分支至 develop
5、删除 assets 分支
$ git flow hotfix finish assets
Switched to branch 'master'
Merge made by the 'recursive' strategy.
assets.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 assets.txt
Switched to branch 'develop'
Merge made by the 'recursive' strategy.
assets.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 assets.txt
Deleted branch hotfix/assets (was 08edb94).
Summary of actions:
- Latest objects have been fetched from 'origin'
- Hotfix branch has been merged into 'master'
- The hotfix was tagged '0.1.1'
- Hotfix branch has been back-merged into 'develop'
- Hotfix branch 'hotfix/assets' has been deleted
补充说明
publish 发布至远程仓库
pull origin 从远程仓库拉下代码
使用场景
背景:
存在 测试环境(test)对应develop分支、预发布环境(pre)对应 release、生产环境(pro)tag,三个环境
开发:
- feature 类型分支尽可能少协作开发,本地开发完成就push至远程 develop 分支由测试人员进行测试
- 项目负责人自我衡量是否发 release
- release 分支测试完成后就可以发布到 pro 环境