How it works
The explanation, with examples you can run.
Trunk-based development
There is one long-lived branch, main. Work happens on short-lived branches (hours to a day or two) or directly on main in small commits, and each change merges as soon as it passes review and CI. Unfinished features are merged too, switched off behind a feature flag or hidden behind an abstraction, so integration never waits for a feature to be complete. Releases are cut from main, either continuously or by tagging, with a short release branch only if a fix has to be backported.
Why teams choose it: conflicts stay small because nobody drifts far from main, CI tests what will actually ship, and deploying becomes routine. What it demands: a fast, reliable test suite, review that keeps up, and the discipline to keep main releasable at every commit.
GitFlow
GitFlow, described by Vincent Driessen in 2010, has main holding only released versions and develop collecting finished features. Features branch from develop, a release/1.4 branch is cut for stabilisation and merged into both main and develop, and hotfix/* branches start from main for urgent fixes. Releases are tagged on main.
It fits products with explicit version numbers where several versions are supported at once: installed software, libraries, firmware. For a web app that deploys continuously it is mostly overhead, and in 2020 its author added a note saying exactly that and suggesting a simpler flow such as GitHub flow (branch from main, open a pull request, merge, deploy).
Pull requests
A pull request (GitLab says merge request) is a hosting-service feature: a proposal to merge a source branch into a target branch, with a diff, line comments, approvals and status checks. Git only provides the branches; the host adds the review. Habits that make them work:
- Keep them small. A few hundred lines get a real review; a few thousand get a skim.
- Let machines check first. Required CI checks, branch protection on
mainand code owners for sensitive paths. - Pick a merge method on purpose. A merge commit keeps the branch's commits and records the join; squash merging turns the pull request into one commit on
main; rebase merging replays each commit with no merge commit. - Open early as a draft to share direction before the work is ready.
To try someone's pull request locally on GitHub, fetch the ref the host keeps for it:
git fetch origin pull/123/head:pr-123git switch pr-123Whatever the workflow, the same rule from the force-push topic applies: rewrite your own branch freely, never a shared one.
Check yourself
3 questions. Get them all right to finish this topic.
0 of 3 right so far. Get all three to finish this topic.