Newer Version Available

This content describes an older version of this product. View Latest

Pull Source from the Scratch Org to Your Project

After you do an initial push, Salesforce DX tracks the changes between your local file system and your scratch org. If you change your scratch org, you usually want to pull those changes to your local project to keep both in sync.

During development, you change files locally in your file system and change the scratch org using the builders and editors that Salesforce supplies. Usually, these changes don’t cause a conflict and involve unique files.

You can use force:source:pull for scratch orgs only. If you’re synchronizing source to any other org, use the Metadata API (force:mdapi:retrieve or force:mdapi:deploy).

Important

By default, only changed source is synced back to your project.

The pull command does not 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 pull command detects a conflict, it terminates the operation and displays the conflict information to the terminal. You can rerun the command with the force option if you want to pull changes from your scratch org to the project despite any detected conflicts.

Before you run the pull command, you can get a list of what’s new, changed, and any conflicts between your local file system and the scratch org by using force:source:status. This way you can choose ahead of time which files to keep.

To pull changed source from the scratch org to the project:

1sfdx force:source:pull

You can indicate either the full scratch org username or an alias. The terminal displays the results of the pull command. This example adds two Apex classes to the scratch org. The classes are then pulled to the project in the default package directory. The pull also indicates which files have changed since the last push and if a conflict exists between a version in your local project and the scratch org.

1STATE    FULL NAME      TYPE       PROJECT PATH
2───────  ─────────────  ─────────  ─────────────────────────────────
3Changed  MyWidgetClass  ApexClass  /classes/MyWidgetClass.cls-meta.xml
4Changed  MyWidgetClass  ApexClass  /classes/MyWidgetClass.cls
5Changed  CoolClass      ApexClass  /classes/CoolClass.cls-meta.xml
6Changed  CoolClass      ApexClass  /classes/CoolClass.cls

To pull source to the project if a conflict has been detected:

1sfdx force:source:pull --forceoverwrite