Removing old hub org, or non-scratch org from Salesforce DX org list
It would be nice for this to be something in the actual CLI commands: the ability to clean up old orgs that are no longer needed.
For the time being, you need to manually cleanup the DX configs in the local installation.
On mac/linux, you can find your DX config folder, called .sfdx
in your user home directory.
cd ~/.sfdx
On windows, you can use %USERPROFILE%\.sfdx
In that folder there are a host of .json
files, named for the username of the admin user you registered for that org. In my case, in this instance it was called [email protected], so sure enough, there it was:
[email protected]
Inside the file, or the hashes for current access token, refresh token, and all the other OAuth goodness that allows DX to access your org. So I simply deleted that file:
> rm [email protected]
That appears to have cleaned it all up, and I'm no longer bothered by the "invalid grant" message and the shadow org.
It looks like rather than deleting a hub org, you just call:
sfdx force:auth:logout -u <hub alias>
You'll get a warning about being sure you want to log out. Once you do, that hub org will no longer show up in the list.
D:\...>sfdx force:org:list
=== Orgs
ALIAS USERNAME ORG ID CONNECTED STATUS
─── ──────────── ────────────────────────────────────────── ────────────────── ────────────────
DevHub [email protected] 00D7F0000000001AAA invalid_grant
I just had my trial Dev Hub org expire (invalid_grant), so I created a new Dev Hub and registered it with sfdx force:auth:web:login -d
.
That moved the (D)
marker to my new dev hub, but the old one was still hanging around. Peter's solution would have worked, but I thought I'd try a sfdx force:org:delete -u DevHub
to see what happens now the old org is no longer the nominated dev hub.
D:\...>sfdx force:org:delete -u DevHub
Enqueue scratch org with name: DevHub for deletion? Are you sure (y/n)?: y
Successfully deleted scratch org DevHub.
Appears to have worked even though it isn't a scratch org. The old dev hub org no longer appears for a sfdx force:org:list