Modern software teams rarely push code directly to the main branch. As projects grow, a clear branching strategy becomes essential to manage features, fixes, and releases while keeping production stable. Branching strategies minimize conflicts, streamline collaboration, and provide a structured workflow for teams of any size.
Gitflow, proposed by Vincent Driessen (A successful Git branching model), is one of the most widely adopted models. It defines a hierarchy of branches and merge policies that ensure smooth development, stable production releases, and a way to address urgent issues without disrupting ongoing work.
Core Branches in Gitflow
Gitflow defines five main branch types, each serving a distinct purpose:
-
main
(ormaster
)- Represents production-ready code.
- Each commit here corresponds to a stable release.
- All merges into
main
should go through pull requests.
-
develop
- Integration branch for ongoing development.
- All completed features are merged here via PRs.
-
feature/*
- For new features or tasks.
- Branch from
develop
and merge back via PRs. - Example:
feature/user-authentication
.
-
release/*
- Prepares a new version release.
- Only bug fixes, documentation updates, or minor tweaks are allowed.
- Merge into both
main
(production) anddevelop
via PRs. - Example:
release/1.2.0
.
-
hotfix/*
- For urgent production fixes.
- Branch from
main
and merge back into bothmain
anddevelop
using PRs. - Example:
hotfix/payment-bug
.
Gitflow in Action
1. Creating a Feature Branch
Imagine implementing user authentication:
# Start from develop
git checkout develop
# Create feature branch
git checkout -b feature/user-authentication
Work on your feature and commit frequently. Once ready, push to the remote and open a pull request into develop
. After code review:
# Merge PR
# Delete feature branch after merge
git branch -d feature/user-authentication
git push origin --delete feature/user-authentication
✅ Feature integrated into develop
safely.
2. Preparing a Release
When development is stable and ready for v1.2.0:
# Branch from develop
git checkout develop
git checkout -b release/1.2.0
git push -u origin release/1.2.0
- Perform final bug fixes, update version numbers, and tweak docs.
- Open a PR to merge
release/1.2.0
intomain
. - Tag the release after merge:
git checkout main
git tag -a v1.2.0 -m "Release 1.2.0"
git push origin v1.2.0
- Merge release back into develop via PR to sync changes.
- Delete the release branch after merging.
3. Handling Hotfixes
Suppose a critical production bug is discovered:
# Branch from main
git checkout main
git checkout -b hotfix/payment-bug
git push -u origin hotfix/payment-bug
- Fix the issue and commit.
- Open a PR to merge
hotfix/payment-bug
into main. - Tag the hotfix release:
git checkout main
git tag -a v1.2.1 -m "Hotfix: Payment bug fixed"
git push origin v1.2.1
- Open a PR to merge hotfix into develop.
- Delete the hotfix branch after merging.
Visualizing Gitflow
-
Feature branches → merge into
develop
via PRs. -
Release branches → merge into
main
via PRs, then back todevelop
. -
Hotfix branches → merge into both
main
anddevelop
via PRs.
Best Practices
-
Use descriptive names:
feature/<task-name>
release/<version>
hotfix/<issue>
- Always use pull requests for merges.
- Delete branches after merging.
- Tag releases for traceability.
- Automate release process using CI/CD pipelines.
Conclusion
Gitflow provides a structured, safe, and collaborative workflow for modern development teams. By isolating features, releases, and hotfixes, it ensures code stability while allowing parallel development. For teams that need speed over structure, a simpler workflow may suffice, but for enterprise-grade software, Gitflow remains a proven approach.
Top comments (0)