Newer Version Available
Push Source to the Scratch Org
The first time you push metadata to the org, all source in the folders you indicated as package directories is pushed to the scratch org to complete the initial setup. At this point, we start change-tracking locally on the file system and remotely in the scratch org to determine which metadata has changed. Let’s say you pushed an Apex class to a scratch org and then decide to modify the class in the scratch org instead of your local file system. The CLI tracks in which local package directory the class was created, so when you pull it back to your project, it knows where it belongs.
During development, you change files locally in your file system and change the scratch org directly using the builders and editors that Salesforce supplies. Usually, these changes don’t cause a conflict and involve unique files.
The push command doesn’t handle merges. Projects and scratch orgs are meant to be used by one developer. Therefore, we don’t anticipate file conflicts or the need to merge. However, if the push command detects a conflict, it terminates the operation and displays the conflict information to the terminal. You can rerun the push command and force the changes in your project to the scratch org.
Before running the push command, you can get a list of what’s new, changed, and the conflicts between your local file system and the scratch org by using force:source:status. This way you can choose ahead of time which version you want to keep and manually address the conflict.
Pushing Source to a Scratch Org
To push changed source to your default scratch org:
1sfdx force:source:push
2
3STATE FULL NAME TYPE PROJECT PATH
4─────── ───────────── ───────── ────────────────────────────────────
5Changed MyWidgetClass ApexClass /classes/MyWidgetClass.cls-meta.xml
6Changed MyWidgetClass ApexClass /classes/MyWidgetClass.clsTo push changed source to a scratch org that’s not the default, you can indicate it by its username or alias:
1sfdx force:source:push --targetusername scratchorg148@acme.com1sfdx force:source:push -u scratchorg148@acme.com1sfdx force:source:push -u MyGroovyScratchOrgSelecting Files to Ignore During Push
It’s likely that you have some files that you don’t want to sync between the project and scratch org. You can have the push command ignore the files you indicate in .forceignore.
If Push Detects Warnings
If you run force:source:push, and warnings occur, the CLI doesn’t push the source. Warnings can occur, for example, if your project source is using an outdated version. If you want to ignore these warnings and push the source to the scratch org, run:
1sfdx force:source:push --ignorewarningsIf Push Detects File Conflicts
If you run force:source:push, and conflicts are detected, the CLI doesn’t push the source.
1STATE FULL NAME TYPE PROJECT PATH
2─────── ───────────── ───────── ─────────────────────────────────
3Conflict NewClass ApexClass /classes/CoolClass.cls-meta.xml
4Conflict NewClass ApexClass /classes/CoolClass.clsNotice that you have a conflict. CoolClass exists in your scratch org but not in the local file system. In this new development paradigm, the local project is the source of truth. Consider if it makes sense to overwrite the conflict in the scratch org.
If conflicts have been detected and you want to override them, here’s how you use the power of the force (overwrite) to push the source to a scratch org.
1sfdx force:source:push --forceoverwriteNext steps:
- To verify that the source was uploaded successfully to the scratch org, open the org in a browser.
- Add some sample test data.