DevToolBoxKOSTENLOS
Blog

Git-Branching-Strategien: GitFlow vs Trunk-Based vs GitHub Flow

12 Min. Lesezeitvon DevToolBox

Why Git Branching Strategies Matter

A Git branching strategy defines how your team creates, names, merges, and deletes branches throughout the software development lifecycle. Without a clear strategy, teams face merge conflicts, broken builds, inconsistent releases, and deployment nightmares. The right branching model depends on your team size, release cadence, and deployment infrastructure.

This guide covers the three most popular branching strategies -- GitFlow, Trunk-Based Development, and GitHub Flow -- with practical examples, comparison tables, and guidelines for choosing the right one for your team.

GitFlow: The Classic Model

GitFlow, introduced by Vincent Driessen in 2010, is the most structured branching model. It uses long-lived branches with specific purposes and strict merge rules. While some consider it complex, it provides excellent control for teams with scheduled releases.

GitFlow Branch Structure

Main Branches (permanent):
├── main          # Production-ready code (tagged releases)
└── develop       # Integration branch for features

Supporting Branches (temporary):
├── feature/*     # New features (from develop, merge to develop)
├── release/*     # Release preparation (from develop, merge to main + develop)
├── hotfix/*      # Production fixes (from main, merge to main + develop)
└── bugfix/*      # Bug fixes (from develop, merge to develop)

GitFlow Workflow

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

# Work on feature...
git add .
git commit -m "feat: add login form component"
git commit -m "feat: implement JWT validation"

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

# 3. Create release branch
git checkout develop
git checkout -b release/2.1.0

# Bump version, fix last-minute bugs
git commit -m "chore: bump version to 2.1.0"
git commit -m "fix: correct validation message typo"

# 4. Finish release (merge to both main and develop)
git checkout main
git merge --no-ff release/2.1.0
git tag -a v2.1.0 -m "Release 2.1.0"

git checkout develop
git merge --no-ff release/2.1.0
git branch -d release/2.1.0

# 5. Hotfix for production bug
git checkout main
git checkout -b hotfix/2.1.1

git commit -m "fix: critical payment processing bug"

git checkout main
git merge --no-ff hotfix/2.1.1
git tag -a v2.1.1 -m "Hotfix 2.1.1"

git checkout develop
git merge --no-ff hotfix/2.1.1
git branch -d hotfix/2.1.1

GitFlow Pros and Cons

ProsCons
Clear separation of concernsComplex for small teams
Supports parallel developmentLong-lived branches cause merge conflicts
Well-suited for versioned releasesSlow release cycle
Strict structure prevents mistakesFeature branches can become stale
Good for regulated industriesOverhead for continuous deployment

Trunk-Based Development

Trunk-Based Development (TBD) is the strategy favored by high-performing engineering teams at Google, Facebook, and Netflix. Developers commit directly to a single trunk branch (usually main) or use very short-lived feature branches that live for at most a day or two.

Trunk-Based Development Structure

Branches:
├── main (trunk)          # The single source of truth
├── feat/login-123        # Short-lived (hours to 1-2 days max)
└── release/2.1           # Optional: release branch cut from trunk

Key Rules:
- Feature branches live < 2 days
- All code merges to trunk daily
- Feature flags hide incomplete work
- Trunk is always deployable
- No long-lived develop branch

Trunk-Based Workflow

# 1. Start small, focused work
git checkout main
git pull origin main
git checkout -b feat/add-search-bar

# 2. Make small commits (1-2 days max)
git add .
git commit -m "feat: add search input component"
git push origin feat/add-search-bar

# 3. Create pull request, get review, merge same day
# After PR approval:
git checkout main
git pull origin main
git merge feat/add-search-bar
git push origin main
git branch -d feat/add-search-bar

# 4. Use feature flags for incomplete features
# config/features.ts
# export const FEATURES = {
#   NEW_SEARCH: process.env.ENABLE_NEW_SEARCH === 'true',
#   DARK_MODE: process.env.ENABLE_DARK_MODE === 'true',
# };

Feature Flags Pattern

// Feature flag implementation for trunk-based development
interface FeatureFlags {
  newCheckout: boolean;
  aiSearch: boolean;
  darkMode: boolean;
}

const defaultFlags: FeatureFlags = {
  newCheckout: false,
  aiSearch: false,
  darkMode: true,
};

// Environment-based flags
function getFeatureFlags(): FeatureFlags {
  return {
    newCheckout: process.env.FF_NEW_CHECKOUT === 'true',
    aiSearch: process.env.FF_AI_SEARCH === 'true',
    darkMode: process.env.FF_DARK_MODE !== 'false',
  };
}

// Usage in components
function CheckoutPage() {
  const flags = getFeatureFlags();

  if (flags.newCheckout) {
    return <NewCheckoutFlow />;
  }
  return <LegacyCheckoutFlow />;
}

// Gradual rollout with percentage
function shouldEnableForUser(userId: string, percentage: number): boolean {
  const hash = hashString(userId);
  return (hash % 100) < percentage;
}

Trunk-Based Pros and Cons

ProsCons
Fewer merge conflictsRequires strong CI/CD
Faster feedback loopsFeature flags add complexity
Always deployable trunkRequires disciplined team
Continuous integrationCode review must be fast
DORA metrics correlationNot ideal for open source

GitHub Flow: The Simple Middle Ground

GitHub Flow is a lightweight, branch-based workflow created by GitHub. It is simpler than GitFlow but more structured than pure trunk-based development. It works well for teams practicing continuous deployment with a single production branch.

GitHub Flow Structure

Branches:
├── main                  # Always deployable to production
├── feature/user-profile  # Feature work
├── fix/login-bug         # Bug fixes
└── docs/api-reference    # Documentation

Rules:
1. main is always deployable
2. Branch off main for any work
3. Open a pull request early
4. Request reviews and discuss
5. Merge to main after approval
6. Deploy immediately after merge

GitHub Flow Workflow

# 1. Create a branch from main
git checkout main
git pull origin main
git checkout -b feature/user-profile

# 2. Make commits with descriptive messages
git add .
git commit -m "feat: add profile page layout"
git commit -m "feat: implement avatar upload"
git commit -m "test: add profile page tests"

# 3. Push and create pull request
git push -u origin feature/user-profile
# Create PR on GitHub with description and reviewers

# 4. Discuss and review
# Team reviews code, CI runs tests
# Make additional commits if needed
git commit -m "fix: address review feedback on avatar sizing"
git push

# 5. Merge after approval
# Use squash merge or merge commit on GitHub
# PR is merged to main

# 6. Deploy
# Automatic deployment triggers after merge to main
# Delete the feature branch
git checkout main
git pull origin main
git branch -d feature/user-profile

GitHub Flow Pros and Cons

ProsCons
Simple to understandNo release branch concept
Great for continuous deploymentLess control over releases
Pull request cultureMain must always be stable
Works for any team sizeNo version separation
Good for SaaS productsHotfixes go through same process

Comparison: All Three Strategies

AspectGitFlowTrunk-BasedGitHub Flow
ComplexityHighLowLow
Main Branchesmain + developmain onlymain only
Feature Branch LifeDays to weeksHours to 1-2 daysDays to a week
Release ProcessRelease branchesFeature flags + deployMerge to main = release
Merge ConflictsFrequentRareModerate
CI/CD RequiredOptionalEssentialRecommended
Best ForVersioned productsSaaS, web appsSaaS, small teams
Team SizeLarge teamsAny (with discipline)Small to medium
Learning CurveSteepModerateEasy
Deployment FreqScheduledMultiple per dayPer merge

Branch Naming Conventions

# Recommended naming patterns
feature/TICKET-123-add-user-auth     # Feature with ticket number
fix/TICKET-456-login-redirect        # Bug fix
hotfix/TICKET-789-payment-crash      # Production hotfix
docs/update-api-reference            # Documentation
chore/upgrade-dependencies           # Maintenance
refactor/simplify-auth-flow          # Code improvement
test/add-integration-tests           # Test coverage

# Commit message convention (Conventional Commits)
feat: add user authentication module
fix: resolve login redirect loop
docs: update API authentication guide
chore: upgrade React to 19.1
refactor: simplify payment processing logic
test: add e2e tests for checkout flow
perf: optimize image loading pipeline
ci: add staging deployment workflow

CI/CD Pipeline Configuration

# .github/workflows/ci.yml - Works with any branching strategy
name: CI/CD Pipeline

on:
  push:
    branches: [main, develop]
  pull_request:
    branches: [main, develop]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: 'npm'
      - run: npm ci
      - run: npm run lint
      - run: npm run test
      - run: npm run build

  deploy-staging:
    needs: test
    if: github.ref == 'refs/heads/develop'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci && npm run build
      - run: npx vercel --yes --token ${{ secrets.VERCEL_TOKEN }}

  deploy-production:
    needs: test
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci && npm run build
      - run: npx vercel --prod --yes --token ${{ secrets.VERCEL_TOKEN }}

Choosing the Right Strategy

Choose GitFlow If:

  • You ship versioned software (mobile apps, desktop apps, libraries)
  • You have scheduled release cycles (monthly, quarterly)
  • Multiple versions need to be maintained in parallel
  • Your team is large (10+ developers) and needs structure
  • You work in regulated industries requiring audit trails

Choose Trunk-Based If:

  • You deploy to production multiple times per day
  • Your team has strong CI/CD infrastructure
  • You are building a web application or SaaS product
  • Your team is experienced and disciplined
  • You want to optimize for DORA metrics

Choose GitHub Flow If:

  • You want simplicity without sacrificing structure
  • Your team is small to medium (2-15 developers)
  • You practice continuous deployment
  • You work on a single production version
  • You are new to branching strategies and want a good starting point

Common Pitfalls to Avoid

  • Long-lived feature branches: Merge daily or use feature flags to avoid painful merge conflicts
  • No branch protection: Always require PR reviews and passing CI checks before merging to main
  • Inconsistent naming: Enforce branch naming conventions with git hooks or CI checks
  • Skipping tests: Every branch should pass the full test suite before merging
  • Not deleting merged branches: Clean up merged branches to keep the repository tidy
  • Force-pushing to shared branches: Never force-push to main or develop
  • Cherry-picking between branches: Prefer merging to avoid lost commits and inconsistencies

Conclusion

The best branching strategy is the one your team consistently follows. Start with GitHub Flow if you are unsure -- it is simple, effective, and easy to adopt. Move to trunk-based development as your CI/CD matures and your team grows more disciplined. Reserve GitFlow for projects that genuinely need versioned releases and parallel version maintenance.

Whatever strategy you choose, invest in automation: branch protection rules, CI/CD pipelines, automated testing, and consistent naming conventions. These practices matter more than the specific branching model you follow.

Practice your Git commands with our Hash Generator and explore other Git commands cheat sheet to improve your workflow.

𝕏 Twitterin LinkedIn
War das hilfreich?

Bleiben Sie informiert

Wöchentliche Dev-Tipps und neue Tools.

Kein Spam. Jederzeit abbestellbar.

Verwandte Tools ausprobieren

{ }JSON Formatter#Hash GeneratorB64Base64 Encoder/Decoder

Verwandte Artikel

Git Rebase vs Merge: Wann welches verwenden (mit visuellen Beispielen)

Den Unterschied zwischen git rebase und merge verstehen. Wann welches verwenden und hÀufige Fehler vermeiden.

Git Befehle Spickzettel: Wichtige Befehle fĂŒr jeden Entwickler

VollstÀndiger Git-Spickzettel: Setup, Branching, Merging, Rebasing, Stashing und erweiterte Workflows.

Git Branch Namenskonvention & Strategie

Best Practices fĂŒr Git Branch Namenskonventionen. Feature/Bugfix/Hotfix-PrĂ€fixe, Git Flow vs GitHub Flow.