Octonote AI
Make your own →

A Git branching workflow that scales

Sunil Tiwari· Oct 12, 2026 · 5 min

Most Git pain in a team does not come from Git. It comes from branches that live for weeks, pull requests nobody can review in one sitting, and a main that is broken often enough that people stop trusting it. The workflow below is a light form of trunk-based development. It works for three people and it still works for three hundred, because it keeps every change small and every merge boring.

From branch to release in under two days
From branch to release in under two days

The idea in one paragraph

There is one long-lived branch, main, and it is always releasable. Every change starts as a short branch off main, goes through a pull request with CI, and comes back as a single squashed commit within a day or two. Releases are tags on main. Unfinished features hide behind feature flags instead of living on a branch for a month.

The shape of history

Branches fork from main, collect a few commits, and return as one commit each. The history on main reads like a changelog: one line per change, each one built and tested.

The shape of history
The shape of history

Compare that with the alternative most teams drift into: release, develop, a dozen half-merged feature branches and merge commits on top of merge commits. Every one of those long-lived branches is a place where conflicts pile up quietly.

The daily loop

Start from a fresh main, branch, commit in small steps, and open the pull request early.

git switch main
git pull --rebase
git switch -c feature/login

# ...work in small commits, each one builds and passes tests...
git add -p
git commit -m "Add login form"

git push -u origin feature/login
gh pr create --fill --draft

A draft pull request costs nothing and gives CI a head start. Mark it ready when the change does what it says.

Two settings make this smoother for everyone:

git config --global pull.rebase true     # never create "merge main into main" commits
git config --global rerere.enabled true  # remember how you resolved a conflict

Keeping a branch fresh, safely

When main moves while you work, replay your commits on top of it instead of merging main into your branch. Your branch stays a clean, short list of commits and the reviewer sees only your change.

git fetch origin
git rebase origin/main
git push --force-with-lease --force-if-includes

Rebasing rewrites your branch, so the push has to be forced. --force-with-lease makes that safe: it only overwrites the remote branch if it still points where you last saw it. If a teammate pushed in the meantime, the push is rejected instead of silently deleting their work. --force-if-includes (Git 2.30 and later) closes the remaining gap, where a background git fetch in your editor updated your view of the remote without you ever looking at it.

Keeping a branch fresh, safely
Keeping a branch fresh, safely

What a good pull request looks like

  • One idea. A reviewer should be able to say what it does in one sentence.
  • Small. Under roughly 400 changed lines, review quality holds up. Above it, reviewers start skimming.
  • Green before review. Lint, tests and build pass before anyone is asked to look.
  • Explains why. The description says why the change exists and how it was tested. The diff already shows what changed.
Merge styleHistory on mainGood for
Squash mergeOne commit per pull requestMost teams. main reads like a changelog
Rebase mergeEvery branch commit, linearTeams that curate each commit carefully
Merge commitBranch commits plus a merge commitLong-lived integration branches (avoid)

Rules that keep main green

  1. Branches live less than two days. If a feature is bigger, ship it in slices behind a flag.
  2. Every change goes through a pull request with required CI checks and at least one approval. Turn on branch protection so nobody, including admins, pushes to main directly.
  3. Squash-merge, so each pull request lands as one revertable commit.
  4. Use a merge queue when the team grows. Two pull requests can each pass CI alone and still break main together. A merge queue tests each one on top of the others before merging.
  5. Release by tagging main. No long-lived release branches.

Releasing

A release is an annotated tag on a commit that already passed CI. The deploy pipeline builds from the tag, so what ships is exactly what was tested.

git switch main && git pull
git tag -a v1.2.0 -m "Login, typo fixes"
git push origin v1.2.0

Version numbers follow semantic versioning: MAJOR.MINOR.PATCH, where a breaking change bumps the major number, a new feature the minor, and a fix the patch.

Fixing a bug in a release

Fix forward on main first, always. A fix that only exists on a release branch will come back in the next release.

Fixing a bug in a release
Fixing a bug in a release

If you only support the latest release, the fix ships with the next tag on main. If customers run an older version you still support, create a release branch from that version's tag only when you need it, and cherry-pick the fix:

git switch -c release/1.1 v1.1.0
git cherry-pick -x 7c4e2a1        # -x records the original commit in the message
git tag -a v1.1.1 -m "Fix session timeout"
git push origin release/1.1 v1.1.1

The release branch exists for that patch and nothing else. New work never starts there.

When things go wrong

  • "I committed to main by accident." Move the commit to a branch: git switch -c fix/oops, then git switch main && git reset --hard origin/main.
  • "My rebase is a mess." git rebase --abort returns you to where you started. If you already finished, git reflog lists every position your branch has had, and git reset --hard <entry> goes back to any of them.
  • "I need to undo a merged change." git revert <sha> on main through a normal pull request. With squash merges that is one commit per change, which is exactly why they pay off.
Short branches are the whole trick. Every other rule here exists to keep them short.
Was this useful?
Written bySunil TiwariMore from Octonote examples →
Make a page like this. Free.Notes and diagrams side by side, written by you or by Claude Code and Codex. Publish it in one click.
Make your own, free