[SalesForce] sfdx force:source:pull ERROR running force:source:pull: Must pass a username and/or OAuth options when creating an AuthInfo instance

sfdx force:source:pull
ERROR running force:source:pull: Must pass a username and/or OAuth options when creating an AuthInfo instance.

before created and opened a new scratch org

Best Answer

The issue is when you create the scratch org you will need to set the default scratch org.

You can set a default username using if you have not set during scratch org creation using below

sfdx force:config:set --defaultusername=<username>

Once you set , you don't need to explicitly indicate in push or pull commands.