The Gitflow Workflow is a structured branching model designed to streamline collaboration and simplify the development process for large teams and complex projects. This page provides an overview of Gitflow, its key components, and how to implement it.
Gitflow is a Git-based workflow introduced by Vincent Driessen. It defines a strict branching model with dedicated branches for:
- Development
- Releases
- Hotfixes
This model is ideal for projects with regular updates and long-term development cycles.
Gitflow uses six main branch types:
-
main
:- The stable branch representing production-ready code.
- Only updated through merges from
release
orhotfix
branches.
-
develop
:- Contains the latest changes for the next release.
- Serves as the integration branch for feature branches.
-
Feature Branches:
- Used for developing specific features.
- Created from
develop
and merged back intodevelop
.
-
Release Branches:
- Used to prepare for a new release.
- Created from
develop
and merged into bothmain
anddevelop
.
-
Hotfix Branches:
- Used to address critical issues in production.
- Created from
main
and merged back into bothmain
anddevelop
.
-
Support Branches (optional):
- Used for maintaining legacy versions of the software.
Initialize Gitflow in your repository:
git flow init
You’ll be prompted to confirm the names for the default branches (main
and develop
) and prefixes for feature, release, and hotfix branches.
Create a feature branch to develop a new feature:
git flow feature start feature-name
When the feature is complete, finish and merge it into develop
:
git flow feature finish feature-name
Create a release branch to prepare for the next version:
git flow release start version-number
Perform final testing, update version numbers, and finish the release. This merges the release into both main
and develop
:
git flow release finish version-number
Create a hotfix branch to fix an urgent issue in production:
git flow hotfix start hotfix-name
After resolving the issue, finish the hotfix. This merges it into both main
and develop
:
git flow hotfix finish hotfix-name
- Organized Workflow: Clearly separates different stages of development.
- Parallel Development: Supports multiple features and hotfixes simultaneously.
- Stable
main
Branch: Ensures production code is always stable. - Team Collaboration: Enables a structured workflow for large teams.
- Complexity: Involves multiple branches and merges, which may be overwhelming for small teams or simple projects.
- Overhead: Not suitable for projects with rapid deployment cycles.
- Use Descriptive Branch Names: Clearly indicate the purpose of each branch, e.g.,
feature/login-page
orhotfix/api-error
. - Test Thoroughly: Test features and releases before merging them into
main
. - Automate Processes: Use CI/CD tools to automate testing, merging, and deployments.
Command | Description |
---|---|
git flow init |
Initialize Gitflow in the repository. |
git flow feature start feature-name |
Start a new feature branch. |
git flow feature finish feature-name |
Merge and delete a feature branch. |
git flow release start version-number |
Create a new release branch. |
git flow release finish version-number |
Finalize the release and merge it into main . |
git flow hotfix start hotfix-name |
Create a new hotfix branch. |
git flow hotfix finish hotfix-name |
Merge and delete the hotfix branch. |
git flow feature start add-login
Develop the feature, commit changes, and finish it:
git flow feature finish add-login
git flow release start 1.0.0
Test, update version numbers, and finalize the release:
git flow release finish 1.0.0
git flow hotfix start fix-crash
Apply the fix and finish the hotfix:
git flow hotfix finish fix-crash
Gitflow is ideal for:
- Projects with scheduled releases.
- Teams requiring clear separation of development stages.
- Applications with long-term support and multiple versions.
The Gitflow workflow provides a well-structured approach to software development, ensuring stability in production and flexibility during development. While it may add complexity, it is highly effective for large projects with organized release cycles.
Next Steps: Rebasing