Mastering Git Flow: Efficient Branching and Release Management
This article explains why teams should adopt Git, outlines its key advantages, discusses common version‑control challenges, and provides a detailed walkthrough of the Git Flow branching model—including production, develop, feature, release, and hotfix branches—plus practical command‑line examples and tool recommendations.
We have switched from SVN to Git for many years, and now almost all projects use GitHub. This article explains why to use Git and how to use it correctly in a team.
Git Advantages
Because it is distributed, every local repository contains the full history of the remote repository.
Excellent branching model; creating and merging branches is fast and easy.
Speed: since all operations are local, branching and merging are quick, saving time in a fast‑paced development environment.
Version Control Challenges
How to start developing a feature without affecting other features?
With many branches created easily, how to manage them and understand their purpose over time?
Which branches have already been merged back to the main line?
How to manage releases, freeze features for a release, and allow continued development of new features during release preparation?
When a bug appears in production, how to fix it quickly and ensure the fix is included in both the developers' branches and the next release?
Git Flow
Just as code needs style guidelines, code management also needs a clear process and standards. Vincent Driessen proposed a successful Git branching model, commonly known as Git Flow.
Below is the Git Flow diagram:
Common Git Flow Branches
Production (master) branch : contains the code that is currently deployed to production. It only receives merges from other branches and should not be modified directly.
Develop branch : the main development line that holds all code intended for the next release. Feature branches are merged into develop.
Feature branch : used to develop a new feature. Once completed, it is merged back into develop.
Release branch : created from develop when preparing a new release. After testing and bug fixing, it is merged into both master and develop, and a tag is created on master.
Hotfix branch : created from master to fix a bug found in production. After fixing, it is merged back into both master and develop, and a tag is added on master.
How Git Flow Works
Initial Branch
All commits on the master branch should be tagged.
Feature Branch
Branch name: feature/* After completing a feature, merge it back into develop and optionally delete the feature branch.
Release Branch
Branch name: release/* Create a release branch from develop, test, fix bugs, then merge it into both master and develop, tag the release on master, and delete the release branch.
Hotfix Branch
Branch name: hotfix/* Create a hotfix branch from master, fix the issue, merge back into master and develop, tag the new version on master, and delete the hotfix branch.
Git Flow Command‑Line Examples
git branch develop git push -u origin develop
git checkout -b some-feature develop # Optionally, push branch to origin: git push -u origin some-feature
git pull origin develop git checkout develop git merge --no-ff some-feature git push origin develop git branch -d some-feature
git checkout -b release-0.1.0 develop
git checkout master git merge --no-ff release-0.1.0 git push git checkout develop git merge --no-ff release-0.1.0 git push git branch -d release-0.1.0 git tag -a v0.1.0 master git push --tags
git checkout -b hotfix-0.1.1 master
git checkout master git merge --no-ff hotfix-0.1.1 git push git checkout develop git merge --no-ff hotfix-0.1.1 git push git branch -d hotfix-0.1.1 git tag -a v0.1.1 master git push --tags
Git Flow Tools
Installation:
OS X: brew install git-flow Linux: apt-get install git-flow Windows:
wget -q -O - --no-check-certificate "https://github.com/nvie/gitflow/raw/develop/contrib/gitflow-installer.sh" | bashUsage: git flow init – initialize a repository for Git Flow. git flow feature start MYFEATURE – start a new feature. git flow feature publish MYFEATURE – publish the feature to the remote. git flow feature pull origin MYFEATURE – fetch a published feature. git flow feature finish MYFEATURE – finish a feature. git flow release start RELEASE [BASE] – start a release. git flow release publish RELEASE – publish a release. git flow release finish RELEASE – finish a release (remember to push tags). git flow hotfix start VERSION [BASENAME] – start a hotfix. git flow hotfix finish VERSION – finish a hotfix.
Git Flow GUI Tools
Many developers prefer graphical tools to avoid remembering commands. The Git Flow script can be used from the command line, and several GUIs integrate it:
SourceTree – supports Git Flow on macOS, Windows, and Linux. After initializing Git Flow, you can start, finish, and publish features, releases, or hotfixes with a few clicks.
Git Flow for Visual Studio – integrates the same workflow directly into Visual Studio.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
21CTO
21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
