Sub topic 4
Comparing branching models for Salesforce
This chapter assumes you know basic Git (branch, merge, pull request). It also assumes you know what Apex classes, objects, and flows are, and that you have worked with sandboxes and production. Earlier chapters covered how metadata is stored as source and how orgs map to places where code lives. Here we compare the three models teams most often pick.
What a branching model has to solve
A Salesforce branching model must answer three questions:
- Where does the next release come from?
- How do changes reach each org, such as a sandbox, UAT, and production?
- How do you ship an urgent fix without dragging along unfinished work?
Salesforce adds a constraint that ordinary web apps lack. The org holds state that Git does not see, such as changes made by admins in Setup. The model you choose has to keep Git and the orgs in step.
The three common models
GitFlow
GitFlow uses long-lived main and develop branches, plus release/* and hotfix/* branches. Features merge into develop. A release branch is cut when develop is ready, then merged to main.
It fits teams with scheduled, infrequent releases. The cost is merge overhead. Metadata files such as profiles and flows conflict often, and long-lived branches make those conflicts larger.
Environment-per-branch
Here each org has a branch: dev, qa, uat, main. A change moves by merging from one branch into the next.
It looks easy to understand, because the branch name matches the org name. The failure mode is drift. A change can reach qa but be held back from uat, and the branches then hold different code. Each org's branch becomes its own version of the truth. Hotfixes are hard because the fix must be merged into every branch by hand.
Trunk-based development
Trunk-based development keeps one long-lived branch, main. Developers cut short-lived feature branches from it, validate them in a pull request, and merge back quickly. The same commit on main is promoted through UAT to production. The next chapter builds this flow in detail.
Side-by-side comparison
| Factor | GitFlow | Environment-per-branch | Trunk-based |
|---|---|---|---|
| Long-lived branches | Two or more | One per org | One |
| Merge conflict risk | High | High | Low if branches stay short |
| Same code in every org | Mostly | Not guaranteed | Yes, by promoting one commit |
| Hotfix effort | Medium | High | Low |
| Fits frequent releases | Poorly | Poorly | Well |
Choosing a model
Use these criteria:
- How often do you release? Weekly or faster points to trunk-based.
- How many people edit the same metadata? More people means shorter branches matter more.
- Do you have a validation step in CI? Trunk-based needs one, because
mainmust always be deployable. - Do you have a compliance rule that forces a release branch? If so, GitFlow's release branches may be required.
Most Salesforce teams do best with trunk-based development. It keeps Git as the source of truth, and orgs become targets of deployment rather than owners of code.
Exercise
Exercise
A team has dev, qa, and uat branches. A bug fix is merged to dev and qa but skipped for uat. Which risk does this show, and which model avoids it?
Show answer
It shows branch drift, where the branches (and so the orgs) hold different code. Trunk-based development avoids it by promoting the same commit from main through every environment.