Creating scratch Orgs with namespaces
Salesforce DX allows us to create multiple scratch Orgs with namespaces equivalent to the packaging organization. In order to do this, the first prerequisite is to link your Dev Org with namespaces to the Developer Hub Org. This process is also known as registering namespaces.
To register a namespace in your Developer Hub Org (if you do not have one, signup using https://developer.Salesforce.com/promotions/Orgs/dx-signup), use the Namespace Register
tab and click on Link Namespace
, as shown in the following screenshot:

Once you click on Link Namespace
, a login for the Salesforce instance pops up. This will be the credentials of the Org where you have namespaced and created your managed packages.
On successfully registering a namespace, you will notice a Namespace Registry
record, as shown in the following screenshot:

Once we register the namespace, we can create a scratch Org with the namespace by indicating the namespace in the sfdx-project.json
file...