Home/Blog/Git Branching Strategies: GitFlow, GitHub Flow, and Trunk-Based Development
Software Engineering

Git Branching Strategies: GitFlow, GitHub Flow, and Trunk-Based Development

Compare Git branching strategies including GitFlow, GitHub Flow, GitLab Flow, and trunk-based development. Learn which strategy fits your team size, release cadence, and workflow.

By Inventive HQ Team
Git Branching Strategies: GitFlow, GitHub Flow, and Trunk-Based Development

Choosing the right Git branching strategy can make or break your team's productivity. The wrong choice leads to merge conflicts, delayed releases, and frustrated developers. This guide compares the three most popular strategies—GitFlow, GitHub Flow, and trunk-based development—helping you choose the right approach for your team.

Branching Strategy Overview

┌─────────────────────────────────────────────────────────────────────────┐
│                    Branching Strategy Comparison                         │
├─────────────────────────────────────────────────────────────────────────┤
│                                                                          │
│  GITFLOW                    GITHUB FLOW           TRUNK-BASED            │
│  ─────────────────────────────────────────────────────────────────────   │
│                                                                          │
│  main ─────●─────────────   main ─────●───────   main ─────●─────────   │
│            │                          │                    │             │
│  develop ──●──●──●──●────            ╱│╲                  ╱│╲            │
│               │     │              ╱  │  ╲              ╱  │  ╲          │
│  feature ────●     │           feat1  │  feat2    commit commit commit   │
│                    │                  │                    │             │
│  release ─────────●              deploy             deploy deploy        │
│                                                                          │
│  Complexity: High            Medium                Low                   │
│  Release: Scheduled          Continuous            Continuous            │
│  Team Size: Large            Small-Medium          Any (with discipline) │
│                                                                          │
└─────────────────────────────────────────────────────────────────────────┘

Strategy 1: GitFlow

GitFlow, created by Vincent Driessen in 2010, uses multiple long-lived branches to manage releases. It's designed for teams with scheduled release cycles.

Branch Structure

BranchPurposeLifetime
mainProduction code, tagged releasesPermanent
developIntegration branch for featuresPermanent
feature/*New feature developmentDays to weeks
release/*Release preparationDays
hotfix/*Emergency production fixesHours to days

GitFlow Workflow

┌─────────────────────────────────────────────────────────────────────────┐
│                         GitFlow Branch Model                             │
├─────────────────────────────────────────────────────────────────────────┤
│                                                                          │
│  main     ●───────────────────────●──────────────────●──────────────    │
│           │                       │                  │                   │
│           │            ┌──────────┘     ┌────────────┘                   │
│           │            │                │                                │
│  hotfix   │            │     ●──●───────┘                                │
│           │            │                                                 │
│  release  │      ●─────●─────────────────●                               │
│           │     ╱                        │                               │
│  develop  ●────●──●──●──●────────────────●──●──●──●─────────────────    │
│                   │        │                  │                          │
│  feature          ●────────●                  ●──●──●                    │
│                                                                          │
│  Legend: ● = commit/merge point                                          │
│                                                                          │
└─────────────────────────────────────────────────────────────────────────┘

GitFlow Commands

# Initialize GitFlow (if using git-flow extension)
git flow init

# Start a feature
git checkout develop
git checkout -b feature/user-authentication

# Finish a feature (merge to develop)
git checkout develop
git merge --no-ff feature/user-authentication
git branch -d feature/user-authentication

# Start a release
git checkout develop
git checkout -b release/v1.2.0

# Finish a release (merge to main and develop)
git checkout main
git merge --no-ff release/v1.2.0
git tag -a v1.2.0 -m "Release version 1.2.0"
git checkout develop
git merge --no-ff release/v1.2.0
git branch -d release/v1.2.0

# Hotfix
git checkout main
git checkout -b hotfix/security-patch
# ... fix the issue
git checkout main
git merge --no-ff hotfix/security-patch
git tag -a v1.2.1 -m "Security patch"
git checkout develop
git merge --no-ff hotfix/security-patch
git branch -d hotfix/security-patch

When to Use GitFlow

Good for:

  • Scheduled release cycles (monthly, quarterly)
  • Teams needing formal QA periods
  • Software with multiple supported versions
  • Compliance requirements needing release documentation
  • Teams already comfortable with Git

Not ideal for:

  • Continuous deployment
  • Small teams (< 5 developers)
  • Rapid iteration environments
  • Teams new to Git

Strategy 2: GitHub Flow

GitHub Flow is a simplified branching model designed for continuous deployment. Created by GitHub, it uses only main and feature branches.

Branch Structure

BranchPurposeLifetime
mainProduction-ready codePermanent
feature/*All development workHours to days

GitHub Flow Workflow

┌─────────────────────────────────────────────────────────────────────────┐
│                        GitHub Flow Model                                 │
├─────────────────────────────────────────────────────────────────────────┤
│                                                                          │
│  main     ●────●────●────●────●────●────●────●────●────●───────────     │
│           │    │    │    │    │    │    │    │    │    │                 │
│           │    ▼    │    ▼    │    ▼    │    ▼    │    ▼                 │
│        deploy  │ deploy  │ deploy  │ deploy  │ deploy  │                 │
│                │         │         │         │         │                 │
│  feature/      ●─────────┘         │         │         │                 │
│  login                             │         │         │                 │
│                                    │         │         │                 │
│  feature/                          ●─────────┘         │                 │
│  dashboard                                             │                 │
│                                                        │                 │
│  feature/                                              ●─────────────    │
│  api-v2                                                (in progress)     │
│                                                                          │
│  Steps: 1. Branch → 2. Commit → 3. PR → 4. Review → 5. Merge → 6. Deploy │
│                                                                          │
└─────────────────────────────────────────────────────────────────────────┘

GitHub Flow Commands

# Create and switch to feature branch
git checkout main
git pull origin main
git checkout -b feature/add-user-dashboard

# Make changes and commit
git add .
git commit -m "feat(dashboard): add user statistics widget"

# Push branch and create PR
git push -u origin feature/add-user-dashboard
# Open PR on GitHub

# After PR approval and merge (on GitHub)
git checkout main
git pull origin main
git branch -d feature/add-user-dashboard

# Deploy happens automatically after merge to main

Pull Request Workflow

  1. Create branch from main
  2. Add commits with descriptive messages
  3. Open pull request describing changes
  4. Discuss and review with team
  5. Deploy from branch (optional, for testing)
  6. Merge after approval
  7. Deploy to production automatically

When to Use GitHub Flow

Good for:

  • Continuous deployment
  • Small to medium teams
  • Web applications and SaaS
  • Teams wanting simplicity
  • Rapid iteration cycles

Not ideal for:

  • Multiple supported versions
  • Formal release processes
  • Long feature development cycles

Strategy 3: Trunk-Based Development

Trunk-based development (TBD) is the most aggressive approach—all developers commit to a single main branch (the "trunk") with minimal or no branching.

Branch Structure

BranchPurposeLifetime
main (trunk)All developmentPermanent
release/*Optional release branchesDays (if used)
Short-lived branchesOptional, < 1 dayHours

Trunk-Based Workflow

┌─────────────────────────────────────────────────────────────────────────┐
│                    Trunk-Based Development                               │
├─────────────────────────────────────────────────────────────────────────┤
│                                                                          │
│  PURE TRUNK-BASED (no branches):                                         │
│                                                                          │
│  main     ●──●──●──●──●──●──●──●──●──●──●──●──●──●──●──●───────────     │
│           │  │  │  │  │  │  │  │  │  │  │  │  │  │  │  │                 │
│           ▼  ▼  ▼  ▼  ▼  ▼  ▼  ▼  ▼  ▼  ▼  ▼  ▼  ▼  ▼  ▼                 │
│        deploy continuously or on every commit                            │
│                                                                          │
│  ─────────────────────────────────────────────────────────────────────   │
│                                                                          │
│  SCALED TRUNK-BASED (short-lived branches):                              │
│                                                                          │
│  main     ●──●──●──●──●──●──●──●──●──●──●──●───────────────────────     │
│              │     │     │     │     │                                   │
│              ●     ●     ●     ●     ●   (branches live < 1 day)         │
│                                                                          │
│  Key: All branches merge within 24 hours, CI runs on every commit        │
│                                                                          │
└─────────────────────────────────────────────────────────────────────────┘

Trunk-Based Commands

# Pull latest, make change, push (no branch)
git checkout main
git pull origin main

# Make your change
vim src/feature.js
git add .
git commit -m "feat: add caching to API calls"

# Push directly to main
git push origin main

# --- OR with short-lived branch ---

git checkout -b quick-fix
# Make change
git add .
git commit -m "fix: resolve null pointer"
git push -u origin quick-fix

# Merge same day via PR
# After merge:
git checkout main
git pull
git branch -d quick-fix

Requirements for Trunk-Based

Trunk-based development requires:

  • Excellent CI/CD: Tests must run fast and catch issues
  • Feature flags: Hide incomplete work in production
  • Small commits: Each commit should be deployable
  • Pair programming: Replaces code review for speed
  • Strong team discipline: Everyone must follow practices

Feature Flags Example

// Feature flag implementation
const features = {
  newDashboard: process.env.FEATURE_NEW_DASHBOARD === 'true',
  betaAPI: process.env.FEATURE_BETA_API === 'true',
};

// Usage in code
function renderDashboard() {
  if (features.newDashboard) {
    return <NewDashboard />;
  }
  return <LegacyDashboard />;
}

// Gradual rollout
const features = {
  newDashboard: userId % 100 < 10, // 10% of users
};

When to Use Trunk-Based

Good for:

  • High-performing teams with strong CI/CD
  • Continuous deployment environments
  • Teams practicing pair programming
  • Organizations like Google, Facebook, Microsoft

Not ideal for:

  • Teams without robust automated testing
  • Open source with external contributors
  • Teams unfamiliar with feature flags
  • Compliance-heavy environments

Strategy Comparison

Decision Matrix

FactorGitFlowGitHub FlowTrunk-Based
ComplexityHighLowLow
Release FrequencyScheduledContinuousContinuous
Best Team SizeLargeSmall-MediumAny
Learning CurveSteepGentleModerate
CI/CD RequirementOptionalImportantCritical
Feature FlagsOptionalHelpfulRequired
Merge ConflictsCommonOccasionalRare
Code ReviewPre-mergePre-mergeOften post-merge
Main StabilityVery stableStableMust be stable
Hotfix SpeedFastFastestFastest

Choosing Your Strategy

┌─────────────────────────────────────────────────────────────────────────┐
│                    Strategy Decision Tree                                │
├─────────────────────────────────────────────────────────────────────────┤
│                                                                          │
│  Do you deploy continuously?                                             │
│  │                                                                       │
│  ├── NO → Do you have scheduled releases?                                │
│  │        │                                                              │
│  │        ├── YES → GitFlow                                              │
│  │        │                                                              │
│  │        └── NO → GitHub Flow (aim for CD)                              │
│  │                                                                       │
│  └── YES → Is your team highly disciplined with excellent CI?            │
│            │                                                             │
│            ├── YES → Trunk-Based Development                             │
│            │                                                             │
│            └── NO → GitHub Flow                                          │
│                                                                          │
└─────────────────────────────────────────────────────────────────────────┘

Branch Protection Rules

Regardless of strategy, protect your main branch:

# GitHub branch protection recommendations
main:
  required_pull_request_reviews:
    required_approving_review_count: 1
    dismiss_stale_reviews: true
  required_status_checks:
    strict: true
    contexts:
      - "ci/tests"
      - "ci/lint"
  enforce_admins: true
  required_linear_history: true  # For GitHub Flow/TBD
  allow_force_pushes: false
  allow_deletions: false

Migration Paths

GitFlow → GitHub Flow

  1. Prepare CI/CD for deploying from main
  2. Merge all active release branches
  3. Delete develop branch (merge to main first)
  4. Update branch protection rules
  5. Train team on simplified workflow
  6. Monitor for issues during transition

GitHub Flow → Trunk-Based

  1. Strengthen CI/CD pipeline (must be fast and reliable)
  2. Implement feature flag system
  3. Reduce PR review cycle time
  4. Start with short-lived branches (< 1 day)
  5. Gradually move to direct commits
  6. Consider pair programming for quality

Best Practices (All Strategies)

Branch Naming Conventions

# Feature branches
feature/PROJ-123-add-user-auth
feature/add-dashboard-widget

# Bug fixes
bugfix/PROJ-456-null-pointer
fix/login-redirect

# Hotfixes
hotfix/security-patch
hotfix/PROJ-789-critical-bug

# Releases (GitFlow)
release/v1.2.0
release/2026-q1

Commit Message Format

Follow Conventional Commits:

feat(auth): add OAuth2 login support
fix(api): resolve rate limiting issue
docs(readme): update installation instructions
refactor(core): simplify data processing pipeline
test(user): add integration tests for signup
chore(deps): update dependencies to latest versions

Keep Branches Short-Lived

StrategyMaximum Branch Age
Trunk-Based1 day
GitHub Flow3-5 days
GitFlow Feature2 weeks
GitFlow Release1 week

Conclusion

The best branching strategy depends on your team's size, release cadence, and deployment practices:

  • GitFlow: Large teams with scheduled releases
  • GitHub Flow: Most teams doing continuous deployment
  • Trunk-Based: High-performing teams with excellent CI/CD

Start simple with GitHub Flow, and only add complexity (GitFlow) or remove it (trunk-based) based on specific needs. Whatever strategy you choose, consistency across the team matters more than the specific approach.

For more Git guidance, see our complete Git & GitHub Guide.

Need Expert IT & Security Guidance?

Our team is ready to help protect and optimize your business technology infrastructure.