Branching strategies and release flow
Pick a workflow that fits your team: trunk-based, feature branches or release branches.
Git does not impose a workflow. Choose one that fits how often you release and how many people work in parallel.
| Strategy | How it works | Good for |
|---|---|---|
| Trunk-based | Everyone merges small changes into main at least daily, behind feature flags when needed | Teams that deploy continuously and have good tests |
| Feature branches + PR | One short-lived branch per change, reviewed and merged into main | Most teams. Keep branches under a few days |
| Release branches | A release/1.4 branch is stabilised while main moves on. Fixes are cherry-picked | Software with versions that must be supported in parallel |
How to merge a PR
- Merge commit: keeps every commit and records the merge. History is accurate and noisy.
- Squash and merge: one commit per PR. History is clean, but you lose the individual commits.
- Rebase and merge: replays commits linearly, with no merge commit.
Protect main
- Require a pull request and at least one review.
- Require the tests (CI) to pass.
- Forbid force pushes and deletion of
main. - Use semantic version tags (
v1.4.2) for releases.
NoteLong-lived branches are the main source of painful merges. Whatever the strategy, the shorter a branch lives, the easier life is.
Test yourself
Answer all the questions, then check them. Finish with every answer right to mark the lesson as done.