Git makes it easy to create branches. A developer can create one in seconds, work independently, and merge the result later. The difficult part is not creating branches; it is deciding how a team should use them without slowing down delivery or destabilizing the application.
A branching strategy defines how code moves from an individual developer's workspace into shared development, testing, staging, and production environments. It influences how teams collaborate, how frequently they integrate changes, how releases are prepared, and how quickly defects can be corrected.
A small team working on an internal application may be comfortable committing directly to a shared branch. A larger team maintaining a customer-facing platform may need pull requests, automated checks, release controls, and a documented hotfix process. A team delivering continuously may find that a traditional release-branch model creates more coordination than value.
There is no universally correct branching strategy. The right choice depends on release frequency, deployment capability, team size, testing maturity, regulatory requirements, and the cost of integrating changes.
This article compares Git Flow, trunk-based development, and GitHub Flow, then explains how to choose and operate a workflow that can grow with a team.
1. Understand the Purpose of a Branch
A Git branch is a movable reference to a commit. It gives developers a separate line of work without requiring a separate copy of the entire repository.
For example:
git switch -c feature/customer-dashboard
This creates and switches to a branch named feature/customer-dashboard.
A developer can now make commits without immediately changing the shared main branch.
git add .
git commit -m "Add customer dashboard layout"
When the work is ready, it can be reviewed and merged into the target branch.
Branches are useful because they allow teams to:
- Develop features independently
- Isolate bug fixes
- Review changes before integration
- Prepare releases
- Experiment without destabilizing shared code
- Coordinate parallel work
However, branches also introduce coordination costs. The longer a branch remains separate from the main line of development, the more its code can diverge from the work happening elsewhere.
That divergence is one of the central problems a branching strategy must control.
2. Git Flow: Structured Branching for Planned Releases
Git Flow is a branching model designed around distinct development and release stages. It is often associated with teams that prepare versioned releases rather than deploying every completed feature immediately.
Its familiar branches include:
- main: production-ready code
- develop: the integration branch for upcoming work
- feature/*: individual features
- release/*: release preparation
- hotfix/*: urgent production corrections
Feature branches
Developers create feature branches from develop.
git switch develop
git pull origin develop
git switch -c feature/user-registration
They implement the feature, commit their work, and open a pull request targeting develop.
git add .
git commit -m "Implement user registration"
git push -u origin feature/user-registration
After review and testing, the branch is merged into develop.
Release branches
When the team decides that a collection of changes is ready for release, it creates a release branch.
git switch develop
git switch -c release/1.2.0
The release branch is used for final stabilization. The team may correct release-blocking bugs, update version information, and verify deployment configuration.
The intention is to stop introducing unrelated features while the release is being prepared.
Once approved, the release is merged into main and the appropriate release changes are reflected back into develop.
Hotfix branches
A hotfix branch addresses an urgent problem in production.
git switch main
git pull origin main
git switch -c hotfix/payment-timeout
The developer fixes the problem, runs the required tests, and submits the change for review. After approval, the hotfix is merged into production and propagated into the development line so that the correction is not lost in a later release.
Advantages of Git Flow
Git Flow provides a recognizable structure for teams that need formal release preparation. It separates ongoing feature development from stabilization and makes hotfix handling explicit.
It can be useful when:
- Releases are planned and versioned
- Multiple supported versions must be maintained
- A formal QA or release approval stage exists
- The team needs a clear distinction between development and production
- Software is distributed to customers on a scheduled release cycle
Limitations of Git Flow
The model introduces several long-lived branches and more merge coordination. If a team deploys several times each day, maintaining a separate develop branch and repeated release branches may become unnecessary overhead.
It can also encourage developers to leave feature branches open for too long. The result may be large merges, integration conflicts, and delayed feedback.
Git Flow is a tool for a particular release environment, not a default requirement for every Git repository.
3. Trunk-Based Development: Integrate Changes Frequently
Trunk-based development centers on a shared main development line, commonly called main or trunk.
Developers integrate small changes frequently. Some teams commit directly to the trunk with strong automated checks; others use short-lived feature branches and pull requests.
The defining characteristic is not the absence of branches. It is the limited lifetime of those branches and the frequency of integration.
A developer might create a short-lived branch:
git switch main
git pull origin main
git switch -c feature/search-filter
After implementing a small change, the developer pushes it and opens a pull request.
git add .
git commit -m "Add search filter"
git push -u origin feature/search-filter
The pull request is reviewed, automated checks run, and the change is merged promptly.
Why short-lived branches matter
Suppose two developers create branches from the same version of main.
Developer A changes the authentication flow. Developer B changes the user profile service.
If both branches remain open for several weeks, each may accumulate changes that the other branch does not know about. When they finally merge, the team may discover conflicts or incompatible assumptions.
If both changes are integrated quickly, problems become visible earlier.
Short-lived branches reduce the amount of code that must be reconciled at integration time.
Feature flags
One challenge is that a feature may take longer to complete than the team wants a branch to remain open.
Feature flags help separate deployment from feature availability.
if (featureFlags.newDashboard) {
return renderNewDashboard();
}
return renderExistingDashboard();
The code can be merged into the main branch while the new feature remains disabled for ordinary users.
Feature flags require discipline. They should have owners, documented defaults, appropriate access controls, and a removal plan. Old flags that remain indefinitely can create confusing code paths and testing complexity.
CI/CD is essential
Trunk-based development works best when every proposed change receives fast, repeatable feedback.
A typical pipeline includes:
- Dependency installation
- Formatting and lint checks
- Static analysis
- Unit tests
- Integration tests where practical
- Build verification
- Security checks
- Deployment or release eligibility checks
The team should aim to detect failures before a change reaches the shared branch.
Advantages
- Smaller integration changes
- Faster feedback
- Less branch divergence
- A simpler view of the current development line
- Good alignment with continuous integration and continuous delivery
Limitations
Trunk-based development is not permission to merge untested code.
Without reliable automated tests, clear ownership, and disciplined reviews, frequent integration can simply move instability into the shared branch.
It may also require feature flags, backward-compatible database changes, and careful release controls for larger systems.
4. GitHub Flow: A Practical Pull-Request Workflow
GitHub Flow is a relatively simple model built around a deployable main branch and feature branches.
The general process is:
- Create a branch from main
- Make a focused change
- Push the branch
- Open a pull request
- Review and test the change
- Merge it
- Deploy according to the team's release process
Example:
git switch main
git pull origin main
git switch -c feature/contact-export
Make the change and commit:
git add .
git commit -m "Add contact export"
git push -u origin feature/contact-export
The developer then opens a pull request against main.
The pull request becomes the central place for code discussion, automated checks, review approval, and change context.
Why teams use GitHub Flow
It avoids maintaining a separate permanent develop branch. The workflow is relatively easy to explain to new contributors and works well when the main branch is kept in a healthy, deployable state.
It is particularly useful for:
- Web applications
- Small and medium engineering teams
- Services that deploy frequently
- Teams using pull requests as their primary review mechanism
- Projects where each change can be tested independently
A deployment consideration
Merging a pull request and deploying it are related but separate decisions.
Some teams deploy automatically after every successful merge. Others deploy to staging first, require approval, or release on a schedule.
A team should document what happens after a merge rather than assuming the branching model defines its deployment policy.
5. Comparing the Three Strategies
| Consideration | Git Flow | Trunk-Based | GitHub Flow |
|---|---|---|---|
| Main structure | Multiple long-lived branches | Shared trunk | Main plus short-lived branches |
| Release model | Planned releases | Frequent integration | Pull-request driven |
| Release branches | Common | Usually limited | Optional |
| Hotfix handling | Explicit hotfix branches | Small urgent changes to trunk | Urgent pull request to main |
| CI importance | High | Very high | High |
| Operational complexity | Higher | Depends on CI maturity | Relatively low |
| Typical fit | Scheduled releases | Continuous integration | Web and product teams |
These are tendencies rather than strict rules. Teams can adapt a model, but they should avoid combining practices without understanding the additional complexity.
Which strategy fits your team?
Choose Git Flow when release management genuinely requires separate development, stabilization, and production lines.
Choose trunk-based development when the team can integrate small changes frequently and has reliable automated validation.
Choose GitHub Flow when a straightforward pull-request process is sufficient and main can remain deployable.
A team should also consider whether it maintains multiple production versions, supports customer-specific releases, or operates under formal approval requirements.
Those constraints may matter more than the number of developers.
6. Branch Protection: Protect the Shared Source of Truth
A branching strategy is incomplete without rules that protect important branches.
On GitHub, branch protection can require pull request reviews, successful status checks, conversation resolution, signed commits, linear history, or deployment checks.
For a production application, a reasonable starting configuration might include:
- Require pull requests before merging into main
- Require at least one approval for meaningful production changes
- Require CI checks to pass
- Require conversations to be resolved
- Restrict force pushes
- Restrict branch deletion
Example GitHub Actions workflow:
name: CI
on:
pull_request:
branches:
- main
jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- name: Install dependencies
run: npm ci
- name: Run lint
run: npm run lint
- name: Run tests
run: npm test
- name: Build
run: npm run build
Branch protection is not a replacement for good reviews. It creates minimum conditions that must be met before important code can be integrated.
7. Common Branching Problems and How to Prevent Them
Problem 1: Long-lived feature branches
A branch that remains open for weeks may accumulate significant differences from main.
Better approach: Break work into smaller, independently mergeable changes. Use feature flags where unfinished functionality must remain hidden.
Problem 2: Oversized pull requests
Large pull requests are difficult to review carefully. Reviewers may focus on whether the code compiles rather than whether the design is correct.
Better approach: Separate refactoring, schema changes, feature implementation, and cleanup where practical.
Problem 3: Treating merge conflicts as the only integration problem
A merge can complete without conflicts and still introduce a logical defect. Two changes may compile independently but behave incorrectly together.
Better approach: Run integration tests and review the behavior of interacting components.
Problem 4: Unclear branch naming
Names such as test, new, or final-update do not communicate intent.
Use predictable names:
feature/customer-exportbugfix/login-redirecthotfix/payment-timeoutchore/update-dependenciesrelease/2.4.0
Problem 5: Rewriting shared history carelessly
Commands such as git push --force can overwrite commits on a shared branch.
Better approach: Use safer practices, avoid force-pushing protected branches, and understand the difference between --force and --force-with-lease before rewriting published history.
Problem 6: Branching without release discipline
A branch model cannot compensate for unclear ownership, untested deployments, or undocumented rollback procedures.
Better approach: Document who approves releases, what tests are required, and how production changes are reversed.
8. A Practical Branching Policy for a Growing Team
A small team can begin with a simple policy:
Branches
- main: production-ready
- feature/*: new functionality
- bugfix/*: non-urgent corrections
- hotfix/*: urgent production fixes
- chore/*: maintenance and dependency updates
Pull requests
- Keep changes focused
- Explain the problem being solved
- Include test evidence
- Identify database or infrastructure changes
- Request an appropriate reviewer
- Resolve review discussions before merging
CI requirements
- Lint
- Type checking
- Unit tests
- Build
- Relevant integration tests
- Security checks appropriate to the project
Release process
- Keep main deployable
- Tag important releases
- Record release notes
- Monitor deployments
- Maintain a tested rollback or recovery process
As the organization grows, the policy can evolve. A team with multiple supported product versions may introduce release branches. A team moving toward continuous delivery may reduce branch lifetimes further.
The important thing is to change the process because the delivery environment requires it, not because a particular branching model is fashionable.
Key Takeaways
- A branching strategy defines how code moves safely from individual work into shared and production environments
- Git Flow is useful when teams need structured, planned releases and explicit stabilization stages
- Trunk-based development emphasizes frequent integration and short-lived branches
- GitHub Flow provides a straightforward pull-request workflow for teams maintaining a deployable main branch
- Branch protection and automated testing are essential safeguards, regardless of the chosen model
Conclusion: The best branching strategy is the one that helps a team integrate changes safely without creating unnecessary delivery friction. A small team may need only main, focused feature branches, pull requests, and automated checks. A product with scheduled releases or several supported versions may need a more structured model. The decision should follow the way the software is built, tested, released, and maintained. A good branching strategy is not measured by how many branches a repository contains. It is measured by how reliably the team can turn reviewed changes into working software.
Published by the DSSS Engineering Team. For corrections or topic requests, use the contact page.