Version controlling using Git-flow tags.

Agnel Nandapurapu
Tensult Blogs
Published in
4 min readFeb 12, 2019

This Blog has been moved from Medium to blogs.tensult.com. All the latest content will be available there. Subscribe to our newsletter to stay updated.

This blog explains step by step process of Git-flow methodology to create versioning in Git. There are so many methods to deploy production code from Git. Generally, one particular branch will be fixed for production deployments, either master branch or another branch. Git-flow also uses the master branch for deployments, but it maintains tags for every production release, so we can easily switch from one release to another by tags.

Installation

Git-flow is a small plug-in for Git. It is available on multiple operating systems. For OSX, we can install using CLI command brew install git-flow. For Window OS use this link to download.

Git-flow has specific branches, each branch has its own role. So I will explain the purpose of each branch with proper commands. Let’s start the process now, just execute below command after successful installation of the Git-flow plug-in.

$ 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 branch
* develop
master

Master and Develop branches :

Git-flow sets master branch for production and develop branch for next release, you can observe that in the above snippet, the master branch is used here for production release history and develop branch for integrating with feature branches.

Feature branches :

Feature branches are for implementation, suppose if we want to work on a particular feature in the project, then we should create a feature branch.

Note : Feature branches should be created from develop branch.

For creating feature branch use below command.

Starting a feature branch :

$git flow feature start featurebranch_01Switched to a new branch 'feature/featurebranch_01'Summary of actions:
- A new branch 'feature/featurebranch_01' was created, based on 'develop'
- You are now on branch 'feature/featurebranch_01'

Feature branch is featurebranch_01. Now, you can work on the feature branch ( featurebranch_01 ). Once work is completed on the feature branch, then we should merge that feature branch into develop branch. Follow below steps to do that.

Finishing a feature branch :

$git flow feature finish featurebranch_01Switched to branch ‘develop’
Updating 8705e32..6b59eca
Fast-forward
xxxxxxx.js | 1 +
xxxx.js | 2 ++
2 files changed, 3 insertions(+)
create mode 100644 xxxxxxx.js
Deleted branch feature/featurebranch_01 (was 6b59eca).
Summary of actions:
- The feature branch ‘feature/featurebranch_01’ was merged into ‘develop’
- Feature branch ‘feature/featurebranch_01’ has been removed
- You are now on branch ‘develop’

If you observe the above summary of actions, it has automatically performed three actions. Same way, we can merge as many feature branches to develop as we wish.

Release branches :

Once develop branch has enough features for a release, then we need to create a release branch.

Note: Release branches should be created from develop branch.

Once release branch is created that means new project cycle is started, so every new feature will be considered for the next release, not for current release, so we shouldn’t merge any feature directly to the release branch, we should only add bug fixes and release notes to release branch.

Starting a release branch :

$ git flow release start 0.1.0Switched to a new branch ‘release/0.1.0’

Release branch is 0.1.0. Now it is contained with all features came from develop branch.

Finishing a release branch :

$ git flow release finish ‘0.1.0’Deleted branch release/0.1.0 (was 6b59eca).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

If you observe the above summary of actions, the release branch is merged with master and develop branches. the release branch is tagged with “0.1.0” and it is removed.

This tag “0.1.0” contains the whole package of release branch “0.1.0”. the same way, every release will be stored into tags ex: 0.1.1, 0.1.2 etc… So we can easily track releases using tags.

Hotfix Branches :

These hotfix branches are used to fix bugs and patches of production releases. Once fixes are completed, it should be merged into both master and develop (or the current release branch), and the master should be tagged with an updated version number.

Starting a hotfix branch :

$ git flow hotfix start hotfixbranch_01Switched to a new branch 'hotfix/hotfixbranch_01'Summary of actions:
- A new branch 'hotfix/hotfixbranch_01' was created, based on 'master'
- You are now on branch 'hotfix/hotfixbranch_01'
Follow-up actions:
- Bump the version number now!
- Start committing your hot fixes
- When done, run:

Finishing a hotfix branch :

$ git flow hotfix finish hotfixbranch_01
Switched to branch 'develop'
Merge made by the 'recursive' strategy.
xxxx.js | 1 -
1 file changed, 1 deletion(-)
Deleted branch hotfix/hotfixbranch_01 (was e9308a9).
Summary of actions:
- Latest objects have been fetched from 'origin'
- Hotfix branch has been merged into 'master'
- The hotfix was tagged 'hotfixbranch_01'
- Hotfix branch has been back-merged into 'develop'
- Hotfix branch 'hotfix/hotfixbranch_01' has been deleted

Note: To check out into tags, use this command.

$git checkout tags/0.1.0

Finally, we should push the master branch and tags to your repository.

$git push 
$git push --tags

Advantages of Git-Flow:

  • Managing of branching system is very easy to understand and doable.
  • All Commands are customized, so we can easily remember commands for a long time.
  • If we follow the Procedure properly then there is no chance of getting conflicts between releases.
  • Maintaining multiple branches in git is a little complicated, which can be maintained easily using Git-Flow.

Conclusion:

Git-Flow has removed some complexities in git and made the process very simple and understandable, so even new guys can understand the flow easily. It is customized for the developmentation environment, so it helps developers/programmers for understanding git easily. Tagging concept of Git-Flow is giving an easy way to track the production releases.

--

--