Using git-flow to automate your git branching workflow
Using git-flow to automate your git branching workflow
Vincent Driessen’s branching model is a git branching and release management strategy that helps developers keep track of features, hotfixes and releases in bigger software projects.
This workflow has lot of commands to type and remember, so there’s also the git-flow library of git subcommands to help automate some parts of the flow to make working with it easier.
After installing git-flow (brew install git-flow
), you can start using git-flow in your repository by using it’s init
command. You can use it in existing projects, but let’s start a new repository:
$ 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? []
git-flow is just a wrapper around existing git commands, so the init
command doesn’t change anything in your repository other than creating branches for you.
If you don’t want to use git-flow anymore, there’s nothing to change or remove, you just stop using the git-flow commands.
If you run git branch
after setting up, you’ll notice that you switched from the master branch to a new one named develop
.
$ git branch
* develop
master
The develop
branch the default branch where most of the work will happen, and the master
branch keeps track of production-ready code.
Feature branches
git-flow makes it easy to work on multiple features at the same time by using feature branches.
To start one, use feature start
with the name of your new feature (in this case, “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
A feature branch was created and you’re automatically switched to it.
Implement your feature in this branch while using git like you normally would.
When you’re finished, use feature finish
:
$ 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'
Your feature branch will be merged and you’re taken back to your develop
branch.
Internally, git-flow used git merge --no-ff feature/authentication
to make sure you don’t lose any historical information about your feature branch before it is removed.
Versioned releases
If you need tagged and versioned releases, you can use git-flow’s release branches to start a new branch when you’re ready to deploy a new version to production.
Like everything else in git-flow, you don’t have to use release branches if you don’t want to.
Prefer to manually git merge --no-ff develop
into master without tagging? No problem.
However, if you’re working on a versioned API or library, release branches might be really useful, and they work exactly like you’d expect:
$ 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'
Bump the version number and do everything that’s required to release your project in the release branch.
I personally wouldn’t do any last minute fixes, but if you do, git-flow will make sure everything is correctly merged into both master
and develop
. Then, finish the release:
$ 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
Boom. git-flow pulls from origin, merges the release branch into master, tags the release and back-merges everything back into develop before removing the release branch.
You’re still on master, so you can deploy before going back to your develop
branch, which git-flow made sure to update with the release changes in master
.
Hotfixing production code
Because you keep your master
branch always in sync with the code that’s on production, you’ll be able to quickly fix any issues on production.
For example, if your assets aren’t loading on production, you’d roll back your deploy and start a hotfix branch:
$ 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'
Hotfix branches are a lot like release branches, except they’re based on master instead of develop. You’re automatically switched to the new hotfix branch so you can start fixing the issue and bumping the minor version number. When you’re done, hotfix finish
:
$ 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
Like when finishing a release branch, the hotfix branch gets merged into both master
and develop
. The release is tagged and the hotfix branch is removed.
Why aren’t you using git-flow?
If you’re not doing versioned releases, Vincent’s git workflow and the git-flow library might not be a right fit for you. However, if you work on a project that’s semantically versioned, like a Rubygem or a versioned API, git-flow will give you a couple of simple commands that will do a lot of work under the hood, making working on features, pushing new releases and hotfixing bugs a lot easier. Well, at least on the git side.
Using git-flow to automate your git branching workflow的更多相关文章
- Git 在团队中的最佳实践--如何正确使用Git Flow
我们已经从SVN 切换到Git很多年了,现在几乎所有的项目都在使用Github管理, 本篇文章讲一下为什么使用Git, 以及如何在团队中正确使用. Git的优点 Git的优点很多,但是这里只列出我认为 ...
- Git 在团队中的最佳实践--如何正确使用Git Flow[转]
原文地址:http://www.cnblogs.com/cnblogsfans/p/5075073.html Git的优点 Git的优点很多,但是这里只列出我认为非常突出的几点. 由于是分布式,所有本 ...
- GIT FLOW 时序图
git flow sequence md link: git branching model master->master branch: use default branch Note rig ...
- 从一个前端项目实践 Git flow 的流程与参考
Git flow 出自 A successful Git branching model,这里使用了一个前端项目配合本文稿实施了 git flow 并记录流程作出示例和参考,对 hotfix 与持续部 ...
- 干货!如何正确使用Git Flow
我们已经从SVN 切换到Git很多年了,现在几乎所有的项目都在使用Github管理, 本篇文章讲一下为什么使用Git, 以及如何在团队中正确使用. Git的优点 Git的优点很多,但是这里只列出我认为 ...
- Git flow 的流程
Git flow 的流程与参考 Git flow 出自 A successful Git branching model,这里使用了一个前端项目配合本文稿实施了 git flow 并记录流程作出示 ...
- 正确使用Git Flow
Git 在团队中的最佳实践--如何正确使用Git Flow 我们已经从SVN 切换到Git很多年了,现在几乎所有的项目都在使用Github管理, 本篇文章讲一下为什么使用Git, 以及如何在团队中正确 ...
- Git 在团队中的使用--如何正确使用Git Flow
Git的优点 Git的优点很多,但是这里只列出我认为非常突出的几点. 由于是分布式,所有本地库包含了远程库的所有内容. 优秀的分支模型,打分支以及合并分支,机器方便. 快速,在这个时间就是金钱的时代, ...
- Git Flow分支策略
就像代码需要代码规范一样,代码管理同样需要一个清晰的流程和规范 Vincent Driessen 同学为了解决这个问题提出了 A Successful Git Branching Model 下面是G ...
随机推荐
- 【2017-04-20】Sql字符串注入式攻击与防御,实体类,数据访问类
字符串攻击 所谓sql字符串注入式攻击就是在用户输入界面输入通过精心编制的含有某种指令的字符串,来改变C#中连接数据库要执行的sql语句,从而对数据库进行攻击性操作 在用户输入界面输入 a');up ...
- 【Hbase学习之二】Hbase 搭建
环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk8 hadoop-3.1.1 hbase-2.1.3 一.单机模 ...
- SpringMVC常用注解的规则(用法)
SpringMVC注解 @RequestMapping用法: a. 用在controller方法上: 标记url到请求方法的映射, 其实就是通过一段url地址, 找到对应需要执行的 ...
- 使用commons-compress解压GBK格式winzip文件到UTF8,以及错误使用ZipArchiveInputStream读出来数据全是空的解决办法
先上正确方法: 正确方式应该为,先创建一个ZipFile,然后对其entries做遍历,每一个entry其实就是一个文件或者文件夹,检测到文件夹的时候创建文件夹,其他情况创建文件,其中使用zipFil ...
- 关于Weex你需要知道的一切
QCon第一天,GMTC全球移动技术大会联席主席.手淘技术老大庄卓然(花名南天)在Keynote上宣布跨平台开发框架Weex开始内测,并将于6月份开源,同时他们也放出官网:http://alibaba ...
- 张春晖让视频的每词每句都可搜索:Autotiming 可以自动配字幕,还将改变哪些领域?
张春晖让视频的每词每句都可搜索:Autotiming 可以自动配字幕,还将改变哪些领域? 对于一些电视观众来说,寻找电视节目字幕中“有趣”的Bug,拍照发到网上与其他人共同嘲笑一下,是一种观看节目之外 ...
- navicat远程连接阿里云ECS上的MYSQL报Lost connection to MySQL server at 'reading initial communication packet'
问题现象 MySQL 远程连接报错:Lost connection to MySQL server at 'reading initial communication packet' 解决方案 1.检 ...
- oracle表分区、表分析及oracle数据泵文件导入导出
1.先说oracle表分区是什么吧 你有500万份文件,你要把他存在磁盘上,好嘛,我们就一个文件夹,500万分文件在那儿杵着,我们想找到要的那个打开,嘿嘿,我们得找到什么时候. 这时候,有个人告诉你, ...
- qt之qmake
qt之qmake qmake 10分钟学会使用qmake 创建一个项目文件 qmake使用储存在项目(.pro)文件中的信息来决定Makefile文件中该生成什么. 一个基本的项目文件包含关于应用程序 ...
- linux 开始
3306 -- mysql 8000--django默认 服务由端口控制 https -- 443 http -- 80 linux发行版:1.centos 免费版的redhat2.ubuntu 乌版 ...