Sub topic 14
Source-tracking conflicts versus Git conflicts
This chapter assumes you can run sf commands against a scratch org or a tracked sandbox. It also assumes you have resolved at least one Git merge conflict, as covered earlier in this tutorial. Both Git and Salesforce CLI use the word "conflict". They mean different things, they are detected by different tools, and they are fixed with different commands. Mixing them up can overwrite work in either your repository or your org.
Two systems, two kinds of conflict
A Git merge conflict happens between two branches in your repository. Git cannot combine two edits to the same lines, so it stops and writes conflict markers into the file. Git knows nothing about any org.
A source-tracking conflict happens between your local project and a Salesforce org. Source tracking is a feature of scratch orgs and of sandboxes with source tracking enabled. The CLI records which components changed locally and which changed in the org. A conflict means the same component changed on both sides since the last sync. The CLI refuses to deploy or retrieve it until you say which side wins. Git is not involved at all.
| Aspect | Git merge conflict | Source-tracking conflict |
|---|---|---|
| Between | Two branches or commits | Local project and an org |
| Detected by | `git merge`, `git pull`, `git rebase` | `sf project deploy start`, `sf project retrieve start`, and their `preview` commands |
| Signal | Markers in the file and exit status 1 | A conflict error listing component names |
| Stored in | The repository history | Tracking data under `.sf/orgs/<org-id>/` |
| Resolved by | Editing the file, then `git add` and `git commit` | Choosing a direction: overwrite the org or overwrite local files |
| Available for production | Yes | No. Production does not support source tracking |
How tracking works
When you create a scratch org, or enable tracking on a sandbox, the CLI keeps two records on your machine. One records the state of your local files at the last sync. The other records the org's revision numbers at the last sync. Both live in the .sf directory, which is normally listed in .gitignore.
When you run sf project deploy start with no source flags, the CLI looks for local changes since the last sync and deploys only those. When you run sf project retrieve start with no source flags, it retrieves only components changed in the org. A component is in conflict when it appears in both lists.
Tracking data is tied to your machine and your org. Another developer working against the same sandbox has their own local record. Your teammate's Git commits do not appear in your tracking data until the files are on your disk.
Where the two conflict types meet
A Git operation changes files on disk. The tracker sees those changes as ordinary local edits. This creates the usual overlap:
- You pull
main. Git merges cleanly and updatesSales_Access.permissionset-meta.xml. - The tracker now lists that permission set as locally changed.
- Meanwhile, a teammate or an admin edited the same permission set in the shared sandbox.
- When you deploy, the CLI finds the component changed on both sides and reports a source-tracking conflict.
Git reported no conflict, and the file may be perfectly valid. The conflict exists only because the org has a different version. The reverse also happens. You resolve a Git conflict by hand, then deploy, and discover the org holds edits that nobody committed.
Finding conflicts before they block you
Use the preview commands. They change nothing and show what a deploy or retrieve would do.
# What would be deployed, and which components conflict with the org?
sf project deploy preview --target-org my-sandbox
# What would be retrieved, and which components conflict with local files?
sf project retrieve preview --target-org my-sandboxEach preview prints a table of components with their state. Components marked as conflicts are the ones the CLI will refuse to move. Read this list before deciding anything. It tells you exactly which files need a human decision.
If you run the real command without previewing, the CLI stops and names the conflicting components. No partial deploy of those components happens.
Resolving a source-tracking conflict
There are only two directions. Pick one per component, based on which version you trust.
Local wins: overwrite the org
Use this when the Git version is the source of truth, which is the normal case on a team that uses version control properly. The org change was a manual edit that should not survive.
sf project deploy start --ignore-conflicts --target-org my-sandboxThis replaces the org's version of every conflicting component. If you want to limit the blast radius, add --source-dir or --metadata so that only specific components are deployed.
Org wins: overwrite local files
Use this when the org holds an edit you want to keep, such as a field permission an admin added through Setup. Commit or stash your local work first. The retrieve overwrites local files, and uncommitted edits in them are lost.
git status # confirm nothing important is uncommitted
sf project retrieve start --ignore-conflicts --target-org my-sandbox
git diff # review what the org version changedAfter the retrieve, git diff shows the org's edits as ordinary local changes. You can review them, keep what you want with git add -p, and commit. This is also the safest way to learn what an admin changed without telling you.
Combining both sides
Tracking has no merge. Each component is taken whole from one side. If you need parts of both, retrieve the org version into a scratch branch, then use Git to combine it with your branch. This turns the problem back into a Git conflict, where you have the marker tools described in earlier chapters. This is the approach to use for profiles and permission sets, where both sides often contain valid, different additions.
git switch -c org-snapshot
sf project retrieve start --ignore-conflicts --target-org my-sandbox
git add -A
git commit -m "Snapshot of sandbox state"
git switch feature/new-field
git merge org-snapshotResetting tracking
Sometimes the tracking data itself is wrong. This happens if you delete the .sf directory, switch machines, or restore a sandbox from a backup. Symptoms are components reported as changed that you did not touch, or conflicts that reappear after you resolve them.
# Rebuild tracking from the current org state, discarding the old record
sf project reset tracking --target-org my-sandbox
# Remove local tracking files for an org that no longer exists
sf project delete tracking --target-org my-sandboxResetting does not change your files or the org. It only changes what the CLI believes is already in sync. After a reset, the CLI treats the org and your project as identical, so any real differences are hidden until you retrieve or deploy something explicitly. Run a retrieve preview and deploy preview first, and only reset once you are sure which side is right.
Common mistakes
- Treating a tracking conflict as a Git problem. Searching the files for
<<<<<<<finds nothing, because tracking conflicts leave no markers. The conflict list is in the CLI output. - Resolving the Git conflict, then deploying blindly. A clean merge says nothing about the org. Always preview before the first deploy after a merge.
- Expecting tracking in production. Production has no tracking. Deploys there use explicit sources, manifests, or
--source-dir, and a conflict cannot be detected by the CLI. Use CI validation and a code review to guard production. - Sharing a sandbox without a process. Several developers deploying to one tracked sandbox will see each other's changes as conflicts. Either give each developer a scratch org or agree on who owns each component.
- Committing the
.sfdirectory. Tracking data describes one machine and one org. Keep it out of the repository.
Exercise
You pull main with no Git conflicts, then run sf project deploy start and the CLI stops with a conflict on Sales_Access.permissionset-meta.xml. An admin added a field permission to that permission set in the sandbox. You want to keep both the admin's change and your branch's change. What do you do, and why is --ignore-conflicts not enough?
Show answer
This is a source-tracking conflict, not a Git conflict. --ignore-conflicts in either direction would discard one side. To keep both, commit your work, retrieve the sandbox version onto a separate branch with sf project retrieve start --ignore-conflicts, commit it, and merge that branch into yours. Resolve any Git conflict markers in the XML, validate the result with xmllint and a deploy dry run, and then deploy.
Exercise
A teammate says, "The deploy failed, so there must be conflict markers left in the file." You grep the project and find none, yet the CLI output lists a conflict. What kind of conflict is it, and what command shows its details without changing anything?
Show answer
It is a source-tracking conflict between your project and the org. Markers appear only for Git merge conflicts. Run sf project deploy preview --target-org <alias> to list the conflicting components without deploying anything.