Sub topic 1
Why Salesforce Changes the Branching Question
Most branching advice assumes that code runs where you build it. A web app's code is compiled, tested, and deployed from a pipeline. On Salesforce, much of what a team builds lives inside an org and is edited there. This chapter explains how that difference affects branching, so the later chapters on workflow and promotion make sense.
Prerequisites
This chapter assumes you have:
- Basic Git use: commit, branch, merge, and pull request.
- Familiarity with Salesforce metadata such as Apex classes, objects, and flows.
- Awareness of sandboxes and production orgs.
- Basic command-line use.
Metadata is the source code
Salesforce describes an org's configuration as metadata. An Apex class, a custom object, a flow, a page layout, and a permission set are each stored as files when you retrieve them. Git can track these files like any other source.
The org holds the running copy. Git holds the history, the review trail, and the intended state. The branching question is therefore how to keep the two in step, not only how to organize code.
Where Salesforce differs from ordinary application code
| Concern | Typical application | Salesforce |
|---|---|---|
| Where changes are made | Local editor | Local editor or directly in an org through Setup |
| Build target | A server or container you recreate | An org with its own data and state |
| Deploy unit | A build artifact | A set of metadata components |
| Test gate | CI test run | Apex tests run in the org during deployment |
| Conflicts | Mostly line-based text | Large XML files that reorder and regenerate |
Each row creates a branching concern.
- Changes made outside Git. Admins can change a flow or a field in Setup without touching a branch. The org can then differ from
main. This is called org drift, and a later chapter covers it. - Orgs are shared and stateful. A sandbox is not rebuilt per commit. Two branches deployed to one sandbox overwrite each other's components.
- Deploys are validated by the org. Apex tests and dependency checks run on the Salesforce side. A pull request can look fine in Git and still fail on deployment.
- Metadata XML conflicts easily. Retrieved files can reorder elements. Two people editing the same profile or flow can produce conflicts that are hard to read.
How the pieces fit together
The flow below shows the loop the rest of this tutorial builds on. Work moves from Git to an org for testing, and anything created in the org must be brought back to Git.
What this means for the branching model
These differences lead to a few design goals for the strategy you will build:
- One branch,
main, represents what the team intends to ship. - Feature work happens on short-lived branches, each tested in its own scratch org or developer sandbox.
- Every pull request is checked by a deployment that does not save anything in the org.
- Changes made directly in an org have a defined path back into Git.
The chapters that follow cover each goal in turn.
Exercise
A teammate fixes a validation rule directly in a shared sandbox through Setup, and nobody commits it. Name two problems this causes for a Git-based workflow.
Show answer
First, the sandbox now differs from main, which is org drift, so the repository no longer describes what is deployed. Second, the next deployment from Git can overwrite the fix, or the fix never reaches production because it was never reviewed or merged. It also gets no pull request validation.