Gitflow Workflow
What is Gitflow?
Gitflow is a branching model for Git that defines a strict branching strategy designed around the project release. It provides a robust framework for managing larger projects.
Branch Types
Main Branches
- main (or master): Contains production-ready code
- develop: Contains the latest development changes
Supporting Branches
- feature/*: Used for developing new features
- release/*: Used for preparing new production releases
- hotfix/*: Used for quickly fixing production issues
Workflow Overview
Feature Development
- Create a feature branch from
develop - Develop the feature
- Merge back to
developwhen complete
Release Preparation
- Create a release branch from
develop - Test and fix bugs
- Merge to
mainand tag the release - Merge back to
develop
Hotfix
- Create a hotfix branch from
main - Fix the issue
- Merge to
mainand tag - Merge back to
develop
Detailed Process
Starting a Feature
# Create feature branch
git checkout -b feature/new-feature develop
# Work on feature
git add .
git commit -m "feat: implement new feature"
# Merge back to develop
git checkout develop
git merge --no-ff feature/new-feature
# Delete feature branch
git branch -d feature/new-feature
Preparing a Release
# Create release branch
git checkout -b release/1.2.0 develop
# Final testing and bug fixes
git commit -m "fix: resolve issue in release"
# Merge to main
git checkout main
git merge --no-ff release/1.2.0
# Tag the release
git tag -a 1.2.0 -m "Release version 1.2.0"
# Merge back to develop
git checkout develop
git merge --no-ff release/1.2.0
# Delete release branch
git branch -d release/1.2.0
Hotfix Process
# Create hotfix branch
git checkout -b hotfix/1.2.1 main
# Fix the issue
git commit -m "fix: critical bug in production"
# Merge to main
git checkout main
git merge --no-ff hotfix/1.2.1
# Tag the hotfix
git tag -a 1.2.1 -m "Hotfix version 1.2.1"
# Merge to develop
git checkout develop
git merge --no-ff hotfix/1.2.1
# Delete hotfix branch
git branch -d hotfix/1.2.1
Branch Naming Conventions
feature/feature-nameorfeature/ISSUE-123-feature-namerelease/1.2.0orrelease/2023-03-21hotfix/critical-bug-fixorhotfix/ISSUE-456-fix
Advantages
- Structured Process: Clear guidelines for development
- Parallel Development: Multiple features can be developed simultaneously
- Release Management: Dedicated branches for release preparation
- Hotfix Support: Quick fixes for production issues
- Version Control: Clear version history with tags
Disadvantages
- Complexity: More complex than simpler workflows
- Merge Conflicts: Frequent merging can lead to conflicts
- Overhead: More branches to manage
- Not Ideal for Small Teams: May be overkill for small projects
When to Use Gitflow
- Large teams with multiple developers
- Projects with scheduled releases
- Complex applications requiring hotfixes
- Teams that need strict release processes
Tools and Integration
Gitflow Extensions
# Install git-flow
brew install git-flow # macOS
sudo apt install git-flow # Ubuntu
# Initialize git-flow in repository
git flow init
# Create feature
git flow feature start new-feature
# Finish feature
git flow feature finish new-feature
GitHub/GitLab Integration
- Protected branches
- Required reviews
- Automated testing
- Release automation
Alternatives
- GitHub Flow: Simpler, main branch only
- GitLab Flow: Environment branches
- Trunk-Based Development: Direct commits to main
Best Practices
- Keep feature branches short-lived
- Regularly merge develop into feature branches
- Use semantic commits
- Tag all releases
- Protect main and develop branches
- Use pull requests for merging
- Automate testing and deployment
Common Issues
Long-Running Feature Branches
- Merge develop frequently
- Consider smaller features
- Use feature toggles
Release Branch Conflicts
- Keep releases short
- Fix only critical bugs
- Communicate with team
Hotfix Complications
- Test hotfixes thoroughly
- Update documentation
- Notify stakeholders
Remember: Gitflow is a framework, not a strict rule. Adapt it to your team's needs.
