I have multiple Devhub orgs. One belongs to my employer. Others belong to external companies that I do consulting work for via my employer.

The latter includes Devhub orgs that define the packaging namespace that I need to reference in the sfdx-project.json for that consulting work.

If I try and directly use the VS Code >SFDX: Create a Default Scratch Org... command it issues the following CLI command:

sfdx force:org:create -f config\project-scratch-def.json --setalias ScratchOrgName --durationdays 7 --setdefaultusername --json --loglevel fatal

That fails with the message:

We don’t recognize this namespace: NamespaceInSfdxProjectJson. Did you register it in your Dev Hub org?

That makes sense, as my default devhub org in the CLI is configured to my be my employers. However, in this case I need to use another Devhub that is configured already in the CLI.

If I was doing this manually I could add a --targetdevhubusername to the CLI command to point it at the correct Devhub for the project. Or I could use force:config:set to change the defaultdevhubusername. Neither of these options is ideal as I need to keep track of which devhub is applicable to the current project.

Is it possible to configure the correct Devhub to use against each project?


My mistake. The force:config:set has options to set the value for both the current directory OR globally.

E.g. Omit the -g and --global parameters to set the config for the current directory/project.

sfdx force:config:set defaultdevhubusername=devhubForCurrentProject@devhub.com

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.