Sub topic 13
Reducing future conflicts
This chapter assumes you can resolve a conflict by hand, as covered earlier. It also assumes you know how a Salesforce DX project is laid out and can run git and sf commands. Here the goal is to have fewer conflicts to resolve.
Match each practice to a cause
Metadata conflicts come from a few repeatable causes. Each practice below removes one of them.
Keep branches short and current
A conflict grows with the time two branches stay apart. Merge from the main branch into your feature branch at least daily, so each conflict stays small and you still remember your own change.
git fetch origin
git merge origin/mainKeep each branch to one change. A branch that touches a dozen unrelated files is more likely to collide with someone else's work.
Split shared files
Profiles are the worst case. One profile holds every field, object and Apex class permission, so every feature branch edits it. Move new access into a permission set for each feature or business function. Two developers adding two permission sets create two files and cannot conflict. Two developers adding to one profile will.
The same idea applies to other large files. Prefer separate files where Salesforce allows it, such as one custom object per file and one flow per file. Do not let a single "catch-all" file collect every change.
Normalize files with .gitattributes
Differences in line endings can make Git see a whole file as changed. Windows and macOS editors often disagree. Commit a .gitattributes file so everyone gets the same endings.
* text=auto eol=lfPair this with a shared formatter configuration, such as a committed Prettier config, so the XML is laid out the same way for every developer. Retrieve with the same Salesforce CLI version across the team, because retrieval output can change between versions.
Let Git remember resolutions
If you rebase often or merge the same branches repeatedly, the same conflict can come back. Turn on rerere (reuse recorded resolution) so Git replays your earlier fix.
git config --global rerere.enabled trueCheck the replayed result anyway. A remembered resolution is still only a guess for the new context.
Agree on team habits
- Announce when you are changing a shared file, such as a profile or a big flow.
- Retrieve only the components you changed. Retrieving a whole profile from an org often pulls in unrelated permissions.
- Review diffs before committing and remove metadata you did not mean to change.
- Run a validation job in CI on every pull request, so conflicts and broken XML show up before the merge.
Summary
| Cause | Practice |
|---|---|
| Branches drift apart | Short branches, daily merge from main |
| Many people edit one file | Permission sets per feature |
| Line endings and layout differ | `.gitattributes`, shared formatter, same CLI version |
| Same conflict repeats | `rerere` |
Exercise
Two developers each add field access for a new field. Both edit the same profile, and the merge conflicts. Name one change to your team's process that would stop this conflict from happening again, and explain why it works.
Show answer
Put field access for each feature in its own permission set instead of the shared profile. Each developer then edits a different file, so Git has nothing to conflict on. Merging main into feature branches daily would also keep any remaining conflicts small.