Sub topic 7
Deploying only your local changes
This chapter assumes you have a Salesforce DX project, the sf CLI installed, and a scratch org authorized with an alias of my-scratch. It also assumes you can read basic Git output. You should already know that scratch orgs support source tracking, and that you can preview changes before moving them.
How a tracked deploy works
In an org with source tracking, sf project deploy start compares your local files against the snapshot the CLI keeps in the .sf directory. It then sends only the components that changed since the last sync. You don't list files, directories, or a manifest.
sf project deploy start --target-org my-scratchIf nothing changed locally, the command reports that there is nothing to deploy and exits.
A worked example
Suppose you edit one Apex class, AccountService, and leave everything else alone.
- Preview what would deploy:
sf project deploy preview --target-org my-scratch- The output lists
AccountServiceas a local change. It also lists any org changes that would conflict. Nothing is deployed yet.
- Deploy:
sf project deploy start --target-org my-scratch- Only
AccountServiceis sent. When the deploy succeeds, the CLI records the new org revision and your local file state. A second run now reports nothing to deploy.
Run the preview first. It costs a second and shows you exactly what the deploy will touch, including conflicts.
What counts as a local change
The CLI treats a component as changed when its local content differs from the stored snapshot. A few details matter:
- Metadata files and their companion files count together. Editing
AccountService.clsalso coversAccountService.cls-meta.xml. - Files matched by
.forceignoreare never tracked, so editing them deploys nothing. - Newly created components are included. Deleted ones are handled separately, which a later chapter covers.
Deploys and conflicts
A tracked deploy refuses to continue if someone changed the same component in the org since your last sync. The error lists the conflicting components. Review them with the preview, then choose a resolution. The override exists, but use it only after reading the preview:
sf project deploy start --target-org my-scratch --ignore-conflictsWith --ignore-conflicts, your local version overwrites the org version. The org-side edit is lost unless you retrieved it first.
Limiting a tracked deploy
Source flags still work in a tracked org. If you pass --source-dir, --metadata, or --manifest, the CLI deploys what you named instead of computing the changes. Use this when you want to push one component while other edits stay local. Be aware that tracking state is updated only for what you deployed.
Common errors
| Symptom | Likely cause | Action |
|---|---|---|
| "No local changes to deploy" | Everything is already synchronized, or the files are in `.forceignore` | Check `git status` and your ignore patterns |
| Conflict error on deploy | The org changed after your last sync | Preview, retrieve or compare, then resolve |
| Deploy fails on a component | A validation or compile error in the metadata | Fix the error shown and rerun. Tracking is not updated for a failed deploy |
| Everything redeploys | Tracking state was reset or the `.sf` folder was deleted | Expected after a reset. Review the preview first |
Exercise
You edited two Apex classes and one Lightning web component in a scratch org project. Another developer's edit to one of the same classes is already in the org. You run sf project deploy start --target-org my-scratch and it stops with a conflict error. What should you do before using --ignore-conflicts, and what would --ignore-conflicts do?
Show answer
Run sf project deploy preview --target-org my-scratch to see which components conflict, then retrieve or compare the org version and merge the edits you want to keep. --ignore-conflicts would deploy your local version over the org version, discarding the other developer's edit to that class.