12 Best Practices for Git Branching Strategies
Choose and run a Git branching strategy: trunk-based vs GitHub flow vs Gitflow, short-lived branches, protection, merge queues and release branches.
The best Git branching strategy for most teams that deploy often is trunk-based development or GitHub flow: one protected main branch, short-lived feature branches merged within a day or two, required checks before merge, and feature flags for unfinished work. Keep release branches or Gitflow for products that ship and support numbered versions.
This guide is about the shape of your branches: which model to pick, how long branches live, how they merge and how releases are cut. It is part of our Git repository management hub. What to write inside each commit is covered in 12 best practices for Git commit messages, and how version control fits the wider delivery pipeline is in 18 best practices for version control in DevOps. Platform features were checked against the GitHub and GitLab documentation and DORA's research pages in November 2026.
Key takeaways
- Pick the model from how you release. Continuous deployment fits trunk-based development or GitHub flow; versioned, installable software may need release branches or Gitflow.
- DORA describes trunk-based teams as having three or fewer active branches and merging to trunk at least once a day.
- Protect the main branch with required reviews and status checks so it stays deployable.
- Hide unfinished work behind feature flags instead of keeping long-lived branches.
- Fix bugs on main first, then cherry-pick to release branches. Never the other way round.
- Choose one merge method per repository and enforce it in settings.
The four common strategies compared
| Strategy | Long-lived branches | How releases happen | Best fit | Main risk |
|---|---|---|---|---|
| Trunk-based development | main only (plus short release branches if needed) | Deploy from main, often several times a day | Teams with strong CI and feature flags | Broken main if tests are weak |
| GitHub flow | main only | Merge a pull request, then deploy | Web apps and services with one live version | Branches that drift if left open |
| Release branches (branch for release) | main + one branch per supported release | Cut release/x.y from main, tag, ship | Mobile apps, SDKs, on-prem products | Forgotten backports |
| Gitflow | main + develop (plus feature, release, hotfix) | Release branch from develop, merge to main, tag | Explicitly versioned software with scheduled releases | Merge conflicts and slow integration |
Gitflow comes from Vincent Driessen's 2010 post "A successful Git branching model". In a 2020 note at the top of that post, he suggests a simpler workflow such as GitHub flow for continuously delivered web apps, and says Gitflow may still suit software that is explicitly versioned or must support several versions in the wild. GitHub flow, as GitHub documents it, has six steps: create a branch, make changes, open a pull request, address review comments, merge, and delete the branch.
For a longer look at the trunk-based approach, read the benefits of adopting trunk-based development in DevOps.
Choosing a strategy
1. Choose the model from your release process, not from habit
Ask three questions before drawing any branch diagram:
- How many versions run in production at once? One (a SaaS service) points to trunk-based or GitHub flow. Several (customers on 3.2, 3.3 and 4.0) means you need release branches.
- How often do you deploy? Daily or more needs short branches and fast CI. Quarterly releases can tolerate a stabilisation branch.
- How good is your automated testing? Trunk-based development depends on CI catching problems within minutes. If tests are thin, fix that first; changing the branch model will not compensate.
Whatever you choose, write it down in CONTRIBUTING.md with a diagram, branch names and who may merge where. A strategy that lives only in a senior engineer's head will drift.
2. Keep the number of long-lived branches small
Every long-lived branch is another line of code that must be kept in sync. DORA's capability page for trunk-based development lists three observable traits: three or fewer active branches in the repository, merging branches to trunk at least once a day, and no code freezes or integration phases. Many teams that think they need develop, qa, staging and prod branches really need one branch and a pipeline that promotes the same build through environments.
3. Do not model environments as branches
Branches named after environments (dev, uat, prod) lead to merges between them, and each merge can produce a slightly different build. Build once from main, tag the artifact, and promote that artifact through environments with pipeline stages and approvals. If you use GitOps, environment differences belong in folders or overlays inside the configuration repository, not in separate long-lived branches.
Working on branches
4. Keep feature branches short-lived
A branch that lives for weeks collects conflicts with every change on main. Aim to merge within a day or two. DORA notes that branches in trunk-based development typically last no more than a few hours. If a feature takes longer, split it into small pieces that each leave main working: a database column first, then the API, then the UI behind a flag.
Update your branch from main often so conflicts appear early and stay small:
git switch feature/checkout-retry
git fetch origin
git rebase origin/main # or: git merge origin/main, if the branch is shared
5. Use feature flags for work that is not ready
Feature flags let you merge incomplete code to main while keeping it switched off in production. That removes the main reason for long-lived feature branches. Give each flag an owner and a removal date, because stale flags become their own kind of technical debt. Read more in why feature flags are critical for trunk-based development.
6. Name branches consistently
Use a type prefix and a short description, optionally with a ticket ID: feature/PROJ-1182-audit-log, fix/token-refresh-race, release/2.4, hotfix/2.4.1. Git allows slashes in branch names, which many tools display as folders. Keep names lowercase with hyphens, and avoid spaces and special characters. Consistent names let you write protection rules and CI triggers with patterns such as release/*. GitLab Premium can enforce a branch name regex through push rules.
Protecting and merging
7. Protect the main branch so it is always deployable
A strategy without enforcement is a suggestion. On GitHub, branch protection rules and rulesets include "Require a pull request before merging" (with required approvals, code owner review and dismissal of stale approvals), "Require status checks to pass before merging", "Require conversation resolution before merging", "Require signed commits", "Require linear history" and "Block force pushes". On GitLab, the default branch is protected by default; you choose roles under "Allowed to merge" and "Allowed to push and merge", and Premium adds "Require approval from code owners".
| Control | GitHub | GitLab |
|---|---|---|
| No direct pushes | Require a pull request before merging | Allowed to push and merge: No one |
| Required approvals | Required approvals count, code owner review | Merge request approval rules; code owner approval (Premium) |
| Green CI before merge | Require status checks to pass | Pipelines must succeed (merge request setting) |
| No history rewrites | Block force pushes (on by default in rulesets) | Allowed to force push: off |
| Test against latest main | Require branches to be up to date, or merge queue | Merged results pipelines, merge trains (Premium) |
See how branch protection rules safeguard production for a walkthrough of each setting.
8. Pick one merge method and enforce it
GitHub offers three methods: a merge commit (the default, created with --no-ff), squash and merge, and rebase and merge. GitLab offers similar choices. Each produces a different history:
- Squash merge: one commit per pull request on main. Easy to revert a whole feature; loses the individual branch commits.
- Rebase merge: linear history that keeps each commit. Every commit must build on its own, so it suits teams with disciplined atomic commits.
- Merge commit: keeps the branch structure and records when it was integrated. History is harder to read with many small branches.
Allow only the method you choose in repository settings, and turn on "Require linear history" if you use squash or rebase. Mixing methods produces a history nobody can read.
9. Use a merge queue on busy branches
Requiring branches to be up to date before merging works for small teams. On a busy repository, it turns into a race where every merge forces everyone else to update and re-run CI. A merge queue solves this. GitHub's merge queue groups approved pull requests and tests each one against the latest target branch plus the pull requests ahead of it. If your required checks run in GitHub Actions, the workflow must trigger on the merge_group event:
on:
pull_request:
merge_group:
GitLab's equivalent is merge trains, available in Premium and Ultimate, which need merged results pipelines turned on.
Releases and hotfixes
10. Cut release branches late and fix on main first
If you support numbered releases, cut release/2.4 from main shortly before the release and allow only fixes on it. The trunk-based development site recommends reproducing a bug on trunk, fixing it there with a test, and then cherry-picking the fix to the release branch. Fixing on the release branch first risks the fix never reaching main, so the bug comes back in the next release.
# Fix lands on main through a normal pull request, then:
git switch release/2.4
git cherry-pick -x 9f3c2e1 # -x records the original commit ID in the message
git push origin release/2.4
Release branches in this model are not merged back into main. Tag the released commit before you eventually delete the branch so the code stays reachable.
11. Tag every release
Tags, not branch names, should identify what shipped. Use annotated tags with Semantic Versioning (v2.4.1) so each tag records who created it and when, and protect tag patterns so nobody moves a release tag after the fact. Most CI systems can trigger a release pipeline on a tag push. The 25 Git commands guide shows the git tag -a and push syntax.
12. Delete merged branches and review the strategy regularly
Merged branches that stay around make it hard to see what is active. Turn on automatic deletion of head branches after merge on GitHub, or the "Delete source branch" option on GitLab merge requests, and run git fetch --prune locally. Then review the strategy itself every few months: count active branches, average branch age and the time from first commit to merge. If branches keep getting older, the strategy or the test suite needs attention.
A starting configuration for a new service
For a team of up to about 15 engineers deploying a web service, this setup is a reasonable default you can adjust:
- Default branch
main, protected: pull request required, one approval, CODEOWNERS review for sensitive paths, status checks required, force pushes blocked. - Squash merge only, linear history required, head branches deleted after merge.
- Branch names
feature/,fix/,chore/; target lifetime under two days. - Feature flags for anything that takes longer than a few days.
- Deploy from main through pipeline stages; annotated SemVer tags for releases.
- Release branches added only if you start supporting more than one version.
Learn branching with real pipelines
Branch models are easier to judge once you have run them with real CI. Our GitLab training covers protected branches, merge request approvals and pipelines, and our DevOps training connects branching to build and deployment. Classes run in Kharadi, Pune and live online across India. Interview questions on this topic are collected in our Git and GitHub interview questions.
Frequently asked questions
Which Git branching strategy is best?
For teams deploying a single live version often, trunk-based development or GitHub flow is usually best. For software that ships numbered versions and supports several at once, add release branches, or use Gitflow if you need a separate integration branch.
Is Gitflow still used?
Yes, mainly for explicitly versioned software with scheduled releases. Its author noted in 2020 that continuously delivered web apps are better served by a simpler workflow such as GitHub flow.
What is the difference between GitHub flow and trunk-based development?
Both use one main branch. GitHub flow always goes through a pull request on a short branch. Trunk-based development can also allow small commits straight to trunk, and stresses very short branches and merging at least once a day.
How long should a feature branch live?
Ideally hours to a day or two. DORA describes trunk-based branches as typically lasting no more than a few hours. Longer work should be split into smaller merges and hidden behind feature flags.
Should I squash, rebase or merge pull requests?
Squash suits most teams because each pull request becomes one revertable commit. Rebase merge suits teams with clean atomic commits. Merge commits keep branch structure. Pick one and disable the others.
Where should hotfixes be made?
On main first, through a normal pull request with a test, then cherry-picked to any supported release branch with git cherry-pick -x. This prevents the fix from missing the next release.
Should I have a branch per environment?
Usually not. Build once from main and promote the same artifact through environments with pipeline stages and approvals. Environment branches cause drift between what was tested and what was deployed.
What is a merge queue?
A merge queue tests approved pull requests against the latest target branch and the changes queued ahead of them, then merges them in order. GitHub calls it merge queue; GitLab calls it merge trains (Premium).
References
- DORA: Trunk-based development capability
- Trunk Based Development: Branch for release
- Vincent Driessen: A successful Git branching model (with 2020 note)
- GitHub Docs: GitHub flow
- GitHub Docs: About protected branches
- GitHub Docs: Available rules for rulesets
- GitHub Docs: About merge methods
- GitHub Docs: Managing a merge queue
- GitLab Docs: Protected branches
- GitLab Docs: Merge trains
- Git documentation: git-cherry-pick
What's Your Reaction?
Like
0
Dislike
0
Love
0
Funny
0
Angry
0
Sad
0
Wow
0