7. Branching Strategies: Git Flow, GitHub Flow, and Trunk-Based Development
Branching strategies define how teams use branches to organize work. The right strategy depends on your team size, release cadence, and deployment practices. This module covers the three most common strategies: Git Flow, GitHub Flow, and Trunk-Based Development. Choosing the right branching strategy is one of the most important decisions a team makes. It affects how you release, how you handle hotfixes, and how you collaborate.
The key insight is that branching strategy is about release management. How often do you release? How do you handle hotfixes? How do you manage features in progress? The right strategy answers these questions. Understanding these strategies helps you choose the right one for your team. There's no one-size-fits-all — each strategy has trade-offs.
This module covers each strategy in depth, including when to use them, their pros and cons, and practical implementation. You'll learn to implement these strategies in real projects.
Git Flow: The Classic Strategy
Git Flow is a comprehensive branching model designed for projects with scheduled releases. It uses two main branches (main and develop) and supporting branches (feature, release, hotfix). It's ideal for applications with traditional release cycles. Git Flow provides clear separation of concerns. Features are developed in feature branches. Releases are prepared in release branches. Hotfixes are applied in hotfix branches. This structure works well for teams with multiple releases per year. The downside is complexity — there are many branches to manage.
Git Flow is best for projects with scheduled releases, like mobile apps or enterprise software. It gives you control over what goes into each release. But it's complex and requires discipline. For teams that release frequently, simpler strategies like GitHub Flow are better.
GitHub Flow: Simple and Continuous
GitHub Flow is a simpler strategy designed for continuous delivery. It has one main branch and feature branches. All changes are made in feature branches and merged to main via pull requests. It's ideal for teams that deploy frequently. GitHub Flow is the default workflow on GitHub. It's simple, fast, and works well for continuous delivery. The main branch is always deployable. Features are developed in branches and merged via PRs. This strategy is popular with SaaS companies and startups.
GitHub Flow is the simplest branching strategy. It's ideal for teams that deploy multiple times per day. The main branch is always production-ready. Features are developed in branches and merged via PRs. There are no release branches because you release constantly. This is the most common workflow in modern software development.
Trunk-Based Development
Trunk-Based Development is a strategy where developers work on a single branch (trunk/main) and integrate frequently. Short-lived feature branches are used, but they're merged to main daily. This strategy is used by high-performance teams like Google and Netflix. Trunk-Based Development emphasizes continuous integration. Developers commit to main multiple times per day. Feature flags control what's released. This strategy requires discipline and automation but enables rapid delivery. It's ideal for teams with strong CI/CD practices.
Trunk-Based Development is the most advanced strategy. It requires excellent CI/CD and discipline. But it enables the fastest delivery. Feature flags hide incomplete features. Developers commit directly to main or to short-lived branches that merge within hours. This is the strategy used by the most high-performing teams.
Step-by-Step: Implementing Branching Strategies
Here's how to implement each branching strategy in practice.
Git Flow Implementation:
1. Create the develop branch: git branch develop
2. For new features: git checkout -b feature/feature-name develop
3. Merge back: git checkout develop && git merge feature/feature-name
4. For releases: git checkout -b release/1.0.0 develop
5. Finalize release: git checkout main && git merge release/1.0.0
6. For hotfixes: git checkout -b hotfix/urgent-fix main
GitHub Flow Implementation:
1. Always branch from main: git checkout -b feature/feature-name main
2. Push and create PR: git push -u origin feature/feature-name
3. After review, merge PR into main
4. Delete the feature branch after merging
5. Deploy immediately after merging to main
Trunk-Based Development Implementation:
1. Everyone works on main: git pull origin main
2. For features, use short-lived branches (max 1 day): git checkout -b feature/feature-name
3. Merge back daily: git merge feature/feature-name
4. Use feature flags to hide incomplete work
5. Run CI on every commit to main
Try It Yourself: Choose a strategy based on your project needs. If you're building a SaaS product with daily deployments, use GitHub Flow. If you're building a mobile app with quarterly releases, use Git Flow. Practice by creating a test repository and implementing your chosen strategy.
Knowledge Check
Ready to test your understanding of 7. Branching Strategies: Git Flow, GitHub Flow, and Trunk-Based Development?