
Andrew Hanna

Andrew Hanna

Mapping Git branches to Salesforce sandboxes means deciding which branch is the source of truth for each environment, so a change moves from dev to production through reviewed merges instead of org-to-org deployments. Long-lived branches map to persistent sandboxes; short-lived feature branches map to scratch orgs and developer sandboxes. Get the mapping right and promotion is just a merge. Get it wrong and you inherit merge-of-merges and silent drift.
This guide is about the mapping mechanics, not the choice of model. If you are still deciding between trunk-based, GitFlow and branch per environment, start with Git branching strategies for Salesforce teams: a decision rule, then come back here to wire it to your orgs.
A branch is only real if there is an org to deploy and test it in. Match each branch to the sandbox type that fits its purpose and refresh cadence:
Refresh cadence caps how many long-lived branches you can genuinely back. Salesforce sets minimum refresh intervals of one day for Developer and Developer Pro, five days for Partial Copy and 29 days for Full, so a branch you cannot refresh is a branch you cannot trust.
Promotion is a merge, not a redeploy. A change starts on a feature branch, then moves up the chain as it clears each gate:
The rule that saves the most pain: never let a branch that maps to production accept a direct commit. Everything reaches it through a reviewed merge, so the branch history is also your deployment history.
Source tracking records which metadata changed in a sandbox, so you pull those changes into the branch instead of guessing at a full retrieve. Deploy from git into the mapped org, and let source tracking flag anything an admin changed directly in that org. That loop keeps the branch as the source of truth and stops the org and the branch from quietly diverging.
Data, org-wide settings and licences live outside the repo, so the mapping only covers metadata. Treat those as environment configuration you seed separately, not as something a branch can promote.
A mapping that lives in an onboarding doc breaks in the first busy release week. Serpent runs a ticket-based workflow with Git in the background, so the branch, its sandbox and the promotion path come from the ticket rather than from memory. More pipeline guides live in our SF Guides library.
Do I need one branch per sandbox?
No. Map long-lived branches only to persistent environments like integration, UAT and production. Use short-lived feature branches for scratch and developer orgs.
Which sandbox should back my UAT branch?
A Partial Copy or Full sandbox, so business users test against representative data rather than an empty developer org.
How is a change promoted between environments?
Through a reviewed merge from one branch to the next, followed by a deploy from git into the mapped org. Promotion is a merge, not a re-deploy from an org.
What keeps a branch and its org from drifting apart?
Source tracking plus deploy-from-git. The branch stays the source of truth, and any direct org change surfaces as a tracked diff to reconcile.
Which branching model should I map first?
Pick the model before the mapping. See our decision rule for choosing by team size and sandbox topology.
Commitment free!