Sub topic 6
Branch names and how long branches live
This chapter assumes you know basic Git (branch, merge, pull request) and have a Salesforce DX project with main as the trunk. Here you will set a naming convention and a rule for how long a branch may live.
Why names and lifetimes matter
A Salesforce branch is a queue of metadata waiting to be deployed. The longer it lives, the more it drifts from main. Flows, profiles, layouts, and permission sets are single files that many people edit. A branch that lives for weeks nearly always collides with one of them.
A good name tells reviewers and automation what the branch is for. A short lifetime keeps merges small and conflicts rare.
A naming convention
Use a type prefix, a slash, and a short kebab-case description. Add a work item ID when your team tracks one.
| Prefix | Use | Example |
|---|---|---|
| `feature/` | New or changed functionality | `feature/case-routing-rules` |
| `fix/` | A bug fix that ships in a normal release | `fix/lead-assignment-null` |
| `hotfix/` | An urgent production fix | `hotfix/fix-opportunity-trigger` |
| `chore/` | Tooling, pipeline, or docs changes | `chore/update-cli-version` |
Follow these rules:
- Use lowercase letters, digits, and hyphens only. Some systems treat case differently, which causes confusing clashes.
- Keep names under about 50 characters.
- Describe the change, not the person. Avoid names like
john-work. - With a tracker, put the ID first:
feature/SF-142-case-routing-rules.
The hotfix/ prefix is useful beyond readability. Your pipeline can match it and run stricter checks or notify the release owner.
How long a branch should live
Aim for a branch that lives one to three days, and treat five working days as a hard limit. Scratch orgs created with --duration-days 7 fit this rhythm. When the org expires, the branch should already be merged.
If work is too big to finish in that time, split it. Two common ways:
- Merge in slices. Ship the custom fields and Apex first, then the flow and page layout in a later branch.
- Hide unfinished work. Use a custom permission, a custom metadata flag, or an inactive flow version so merged code does not change behavior until you switch it on.
Keeping a branch current
While a branch is open, bring in changes from main at least once a day. This surfaces conflicts while they are small.
git fetch origin
git switch feature/case-routing-rules
git merge origin/mainTeams that prefer a linear history can use git rebase origin/main instead. Pick one approach and use it consistently. If the branch is shared, do not rebase it.
Cleaning up
Delete a branch right after its pull request merges. Most Git hosts can do this automatically. Locally, remove the stale reference and the branch:
git fetch --prune
git branch -d feature/case-routing-rulesAlso delete the scratch org so you do not hit the org limit:
sf org delete scratch --target-org case-routing --no-promptCommon errors
- Naming a branch after a person or a sprint. Neither describes the change.
- Keeping a long-lived
developor per-environment branch alongsidemain. The previous chapter's trunk-based model avoids this. - Reusing a branch name after a merge. Old remote references cause confusing pull request history.
- Leaving finished branches undeleted, so nobody knows what is still in progress.
Exercise
A teammate has a branch called sprint-14-stuff that has been open for three weeks and contains a new flow, two objects, and several Apex classes. Name two changes you would ask for, and give a better branch name for the first slice if it contains only the two objects.
Show answer
Ask them to (1) rename or recreate the work using the type/description convention, and (2) split it into smaller branches that each merge within a few days, merging in current main first to reduce conflicts. Hidden or inactive work, such as an inactive flow version, can let unfinished pieces merge safely. A good name for the first slice is feature/add-routing-objects, or feature/SF-142-add-routing-objects if the team uses work item IDs.