Lesson 1 of 28Git in a team
Branching Strategies Teams Use
Trunk-based development, GitHub flow, GitFlow and release branches: how real teams branch, protect main and keep merges small.
On your first week at a new job you clone the repo and find main, develop, forty stale branches called things like johns-fix-2 and a wiki page titled "Release process (DO NOT SKIP)". Or you find only main and a rule that nobody can push to it. The branching strategy decides how often you integrate, how painful your merges are, how releases happen and how fast a bug fix reaches users. You rarely get to choose it on day one, but you need to recognise which one you are in, work well inside it, and know enough to argue for a better one later.
The one idea underneath every strategy
Every branching strategy is an answer to one question: how long does work stay apart before it is combined? While your branch is open, main keeps moving. Every day you wait, more of your teammates' changes pile up between your branch and the current code, and the merge at the end gets bigger and riskier. That is integration debt, and it grows faster than linearly because changes start interacting with each other.
You can see the shape of it with a quick simulation. Five teammates each merge one small PR a day into a codebase of 400 files with a few hot files that everyone touches (routes, settings, shared types). Your branch edits six files. How likely is it that someone else changed one of your files while your branch was open?
Press Run (⌘ Enter) to see what happens.A one-day branch overlaps with someone about a quarter of the time. A two-week branch almost always does, and there are several files to reconcile, each one a chance for a conflict or, worse, a change that merges cleanly but no longer works. Change the numbers and the curve moves, but its shape stays the same. Everything that follows is a different way of managing that curve.
Trunk-based development
In trunk-based development everyone integrates into one shared branch (the trunk, which is main in most repos) at least once a day. Branches still exist, but they are tiny: a few hours to a day or two of work, one reviewer, merged and deleted. main is kept releasable at all times, so any commit on it could go to production.
DORA's research programme lists trunk-based development as one of the capabilities that predicts better software delivery. Its description is concrete: few active branches (three or fewer), merging into trunk at least daily, and no code freezes or separate integration phases. The point is not the branch count itself. Teams that integrate continuously find conflicts while they are small and find broken assumptions the same day.
Trunk-based development only works with support around it:
- Fast, trusted CI on every PR, so a broken change is caught before it reaches
main. - Small PRs. You split a feature into slices that are each safe to merge on their own: the database column first, then the API that writes it, then the UI.
- Feature flags for work that is not ready for users. The code ships dark behind a flag that is off in production, and you switch it on when the whole feature is done. CI/CD and Release Practices covers flags properly; for now, know that a flag replaces a long-lived branch.
GitHub flow: the common default
Most product teams you join will use something close to GitHub flow, which is trunk-based development described as a PR workflow:
- Branch from an up-to-date
main. - Commit, push, and open a pull request (often as a draft early on).
- CI runs; teammates review.
- Merge into
main. maindeploys, automatically or with one click.
That is the whole model. There is no develop branch and no release branch. Its strength is that there is only one place code can be, so nobody asks "is this fix in develop or main?" Its weakness is that it assumes you deploy one version of the software, continuously. That is true for web apps and APIs. It is not true for everything.
GitFlow: where it came from and where it fits
GitFlow was published by Vincent Driessen in 2010 and became very popular. It uses two permanent branches and three kinds of temporary ones:
mainholds only released code, with a tag per version.developis where finished features are integrated.feature/*branches come offdevelopand merge back into it.release/*branches are cut fromdevelopto stabilise a version, then merge into bothmainanddevelop.hotfix/*branches come offmainfor urgent fixes, then merge into bothmainanddevelop.
main only ever holds released code. M1 is tagged v1.0.
In 2020 Driessen added a note to his original article: for software that is delivered continuously, such as web apps, he recommends a simpler workflow like GitHub flow. GitFlow still fits software with explicit versions, especially when several versions are supported in the wild at once. You will still meet it in older companies, agencies and some enterprise teams, often because nobody revisited the decision. Inside it, keep your feature branches as short as you can and always check that hotfixes reached develop.
Release branches without GitFlow
Some software cannot deploy every merge. Mobile apps go through app store review. On-premise and desktop products ship versions that customers install and keep for years. Libraries maintain several major versions. These teams usually stay trunk-based for development and add release branches: at release time they cut release/2.4 from main, test and ship from it, and only fixes land there afterwards.
The rule that keeps this sane is upstream first: fix the bug on main, then copy the fix onto the release branch with a cherry-pick. If you fix it only on the release branch, the next release, cut from main, brings the bug back.
git switch maingit pull# the fix was merged to main as commit 3f9c2abgit switch release/2.4git cherry-pick -x 3f9c2ab # -x records "(cherry picked from commit ...)"git pushgit tag v2.4.1 && git push origin v2.4.1The -x flag appends the original hash to the message, so anyone reading the release branch can trace the fix back to its PR.
A crash is reported in version 2.4, which customers run, while main has moved on toward 2.5. Order the steps under an upstream-first policy.
- Tap the steps below in the right order.
Long-lived feature branches and merge hell
The most expensive pattern is a big feature built on one branch for weeks. It feels safe because nothing reaches main until it is done. In practice the merge at the end touches dozens of files that others changed in the meantime, nobody can review a 4,000-line PR properly, and the integration bugs surface during the release instead of during development. Teams then try to fix it by merging main into the feature branch every day, which helps, but the review problem remains.
The fix is to merge incomplete work safely: small PRs behind a flag, refactors merged first as their own PRs, and new code paths added next to old ones and switched over later. If you are told "keep it on a branch until it is finished", it is worth asking whether a flag would be possible instead.
Match each team to the strategy that fits it best.
Protecting main
A strategy is only real if the repository enforces it. On GitHub you do this with branch protection rules or the newer rulesets, which can target many branches by pattern and be applied across an organisation. The usual settings for main:
- Require a pull request with at least one approving review, and dismiss approvals when new commits are pushed.
- Require status checks to pass, choosing the CI jobs that must be green.
- Require branches to be up to date before merging, so checks ran against the latest
main. - Require linear history, which blocks merge commits and forces squash or rebase merges. Rebase, Merge and Squash explains the trade-off.
- Block force pushes and deletion.
A CODEOWNERS file (in .github/, the repo root or docs/) maps paths to people or teams. With "require review from code owners" turned on, a change to infra/ or migrations/ cannot merge without that team's approval.
# Last matching pattern wins
* @acme/web-team
/migrations/ @acme/data-team
/infra/ @acme/platform
/.github/workflows/ @acme/platformMerge queues
On a busy repo, "require up to date" becomes a race. Ten PRs are green, one merges, and the other nine are now out of date, so everyone clicks "update branch" and waits for CI again. A merge queue (GitHub has one built in, and GitLab has merge trains) solves this. You add an approved PR to the queue; the queue builds a temporary branch of main plus the PRs ahead of yours, runs CI on that exact combination, and merges only if it passes.
Both PRs are approved and green against the main they started from. Instead of merging, the authors add them to the queue.
Naming branches and linking tickets
Teams usually agree a branch naming pattern so branches sort, filter and link to tickets automatically:
git switch -c feat/PAY-482-refund-webhookgit switch -c fix/PAY-497-null-currencygit switch -c chore/bump-node-24A type prefix (feat, fix, chore, docs), the ticket key, and three or four words. Tools like Jira link a branch, its commits and its PR to the ticket when the key appears in the branch name or message, and on GitHub a PR description containing Closes #123 closes that issue when the PR merges. Match whatever the repo already does; consistency matters more than the exact format. Delete branches after merging (GitHub can do it automatically) so the branch list stays meaningful.
Stacked branches for large work
Sometimes a change is genuinely large: a new payments provider needs a schema change, a client library, an API and a UI. Instead of one huge PR, you stack them: branch 2 starts from branch 1, branch 3 from branch 2, and each PR shows only its own slice. Reviewers get four focused PRs, and the bottom of the stack can merge while you are still writing the top.
The cost is upkeep. When review feedback changes branch 1, every branch above it has to be moved onto the new commits. Git does this in one command with git rebase --update-refs, run from the top branch, which also moves every branch pointer in the stack. Rebase, Merge and Squash shows it in action. Tools such as Graphite build a review workflow around stacks, and many teams that work this way set rebase.updateRefs to true in their Git config.
schema then api then ui, each a PR on the one below. What is the main benefit over one big PR?How this course is laid out
- Git in a team and Pull requests and code review: branching, rebasing, conflicts, recovery, clean commits, and getting changes reviewed and merged.
- Working in real codebases: reading code you did not write, changing legacy code safely, and keeping a test suite trusted.
- Writing that engineers read: READMEs, runbooks, design docs, RFCs, ADRs and async updates.
- How teams plan and ship: Agile in practice, tickets and estimates, CI/CD, feature flags and versioning.
- Production ownership: observability, on-call, incidents, postmortems and security hygiene.
- Growing your career: your first 90 days, working with product and design, remote work and mentoring, and the career ladder.
By the end you can join a team and work the way it does, from your first pull request to your first page. The course closes with a wrap-up that follows one feature through all of it.
- trunk-based development
- Everyone integrates small changes into one shared branch at least daily, keeping it releasable at all times.
- GitHub flow
- Branch from main, open a PR, review and CI, merge, deploy. The common default for web teams.
- GitFlow
- A model with permanent main and develop branches plus feature, release and hotfix branches, suited to versioned releases.
- release branch
- A branch cut from main for one version that only receives cherry-picked fixes.
- branch protection
- Repository rules for a branch: required reviews and checks, linear history, no force pushes.
- merge queue
- A queue that tests main plus the PRs ahead of yours together and merges only combinations that pass.
- stacked PRs
- A chain of small branches, each built on the one below, reviewed and merged in order.