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).
- Developer creates branch
feat/login-page. - Writes code.
- Opens PR.
- CI/CD runs tests.
- Code merges to
main. mainautomatically 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~3Change 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#
| Feature | GitFlow | Trunk-Based |
|---|---|---|
| Release Speed | Slow (Scheduled) | Fast (Continuous) |
| Complexity | High | Low |
| Ideal For | Legacy Software | SaaS / Web Apps |