Mahesh's blog
Published on

git flow makes branching easy

Branching model is essential to master for anyone working in a distributed environment involving multiple developers working on the same repository. Refer here for branching model: http://nvie.com/posts/a-successful-git-branching-model/

git makes it easier to create and switch branches within repository but when it comes to following above branching model, we need to manually run and maintain. This is where git flow helps teams and developers to follow branching model in git.

For installing git flow, https://github.com/nvie/gitflow/wiki/Installation

Commands

To start git flow, we need to initialize by running following command:

git flow init

Initialize command will set basic branches like master, develop needed for git flow to create or merge branches during development.

For starting feature, git flow feature start feature-1 . This will create feature branch from develop branch and checkout to that branch.

Once feature development is complete, branch can be pushed to remote with this command: git flow feature publish feature-1

If feature is complete and code reviewed via pull request, branch can be merged with this command: git flow feature finish feature-1

The above command merges changes to develop branch.

feature workflow can be used for bugfixes well by replacing feature with bugfix in above commands.

To push these changes to master branch for release, release branch has to be created similar to feature workflow but target branch used by git flow is master branch. Here are commands for release:

git flow release start v.20180128
git flow release finish v.20180128
git push --tags
git push origin master
  • start command will create a branch from develop
  • finish will merge changes to master branch and then merge those changes back to develop
  • pushes tags created during merge to indicate tags

For production defects or support development, hotfix and support are used instead of release in the above release related commands.

git aliases which might be useful:

alias gffs 'git flow feature start'
alias gfff 'git flow feature finish'
alias gffp 'git flow feature publish'
alias gfrs 'git flow release start'
alias gfrf 'git flow release finish'
alias gfrp 'git flow release publish'
alias gfhs 'git flow hotfix start'
alias gfhf 'git flow hotfix finish'
alias gfhp 'git flow hotfix publish'
alias gfbs 'git flow bugfix start'
alias gfbf 'git flow bugfix finish'
alias gfbp 'git flow bugfix publish'

References