Skip to main content

Git Workflows: Trunk-Based Development vs GitFlow

Git is more than commit and push. It’s how teams communicate. Your branching strategy determines your deployment velocity.

1. GitFlow (The Old Way)
#

GitFlow involves two long-running branches: main and develop.

  • Pros: strict control, clear release versions.
  • Cons: Merge conflicts hell, slow deployment cycle.

2. Trunk-Based Development (The Modern Way)
#

Everyone pushes to main (or short-lived feature branches that merge to main within hours).

  1. Developer creates branch feat/login-page.
  2. Writes code.
  3. Opens PR.
  4. CI/CD runs tests.
  5. Code merges to main.
  6. main automatically deploys to Staging.
gitGraph
   commit
   branch feature-A
   checkout feature-A
   commit
   commit
   checkout main
   merge feature-A
   commit
   branch feature-B
   checkout feature-B
   commit
   checkout main
   merge feature-B
   commit

3. Advanced Scenarios
#

The Interactive Rebase
#

Before merging your branch, clean up your history.

# Combine the last 3 commits into one
git rebase -i HEAD~3

Change pick to squash for the commits you want to combine.

The Cherry Pick
#

Need a specific hotfix from another branch without merging everything?

git cherry-pick <commit-hash>

The “Oh No, I Committed to Main” Protocol
#

# 1. Reset main to the previous commit (keeping changes)
git reset --soft HEAD~1

# 2. Create a new branch
git checkout -b my-feature-branch

# 3. Commit there
git commit -m "Saved my work"

4. Branch Protection Rules
#

If you use GitHub, enable these settings on main:

  • Require pull request reviews before merging.
  • Require status checks to pass before merging (CI/CD).
  • Require linear history (no merge commits, only rebase/squash).

Comparison
#

FeatureGitFlowTrunk-Based
Release SpeedSlow (Scheduled)Fast (Continuous)
ComplexityHighLow
Ideal ForLegacy SoftwareSaaS / Web Apps
Verdict: Use Trunk-Based