Git Branching Strategies: GitHub Flow, Trunk, Merge vs Rebase
You will practice short-lived feature branches and compare merge versus rebase to keep history readable. By the end you will choose a branching workflow that keeps main always releasable.
Learning Objectives
- Compare GitHub Flow, trunk-based, and GitFlow trade-offs.
- Integrate work with merge and with rebase.
- Keep main releasable with short-lived branches.
- Time: ~3 hours · Difficulty: Intermediate · Prereqs: the Git fundamentals lab.
Architecture Overview
gitGraph
commit id: "main"
branch feature
commit id: "work-1"
commit id: "work-2"
checkout main
merge feature
Environment Setup
You will need: Git and a repo with a couple of branches.
Before you begin: never rebase commits that others have already pulled.
Step-by-Step Execution
01
Create a short-lived feature branch
git switch -c feature/api && git commit -am "add endpoint"02
Integrate with merge (preserves history)
git switch main && git merge --no-ff feature/api03
Or rebase for a linear history
$ git switch feature/api && git rebase main
Successfully rebased and updated refs/heads/feature/api.
Progress So Far
graph LR
A[01 Feature branch] -->|done| B[02 Merge]
B -->|alt| C[03 Rebase]
style A fill:#1a4a1a,stroke:#00ff00,color:#fff
style B fill:#1a4a1a,stroke:#00ff00,color:#fff
style C fill:#1a4a1a,stroke:#00ff00,color:#fff
Testing & Validation
git log --oneline --graph --allA merge shows a branch-and-join graph; a rebase shows a straight line. Pick the one your team prefers and keep main green.
Troubleshooting
- Rebase rewrote shared history: only rebase local, un-pushed work; otherwise merge.
- Long-lived branches diverge: keep branches short to avoid painful integrations.
- Mid-rebase confusion: abort safely with
git rebase --abort.
Extension Ideas
- Gate merges with reviews in Pull Requests.
- Resolve conflicts confidently in Merge Conflict Resolution.
- Protect main with required CI in GitHub Actions.
Key Results
- Integrated a feature with both merge and rebase.
- Produced a readable history matching the chosen strategy.
- Kept main releasable with short-lived branches.
- Understood when rebase is safe versus dangerous.