Stack Exchange Network
Stack Exchange network consists of 181 Q&A communities including
Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack Exchange
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this community
Anybody can ask a question
The best answers are voted up and rise to the top
3 years, 5 months ago
I have an org connected in
sfdx with an alias that I would like to change.
I don't see an
alias key in the corresponding
~/.sfdx/org.json file. I also don't see anything mentioned about this on the
org commands documentation.
Is there a way to do this via
sfdx-cli without connecting to or creating the org again?
Jan 8, 2020 at 18:25
1,014 1 1 gold badge 8 8 silver badges 19 19 bronze badges
You can use force:alias:set:
sfdx force:alias:set newAliasfirstname.lastname@example.org
The original alias is automatically removed/renamed with this command.
Jan 8, 2020 at 18:49
468k 19 19 gold badges 428 428 silver badges 769 769 bronze badges
I'm not sure if the spec changed for
sfdx force:alias:set but the command that worked for me involved specifying the username, as follows:
sfdx force:alias:set email@example.com
Then the results of
sfdx force:org:list is as follows:
ALIAS USERNAME ORG ID EXPIRATION DATE
─────────── ───────────────────────────── ────────────────── ───────────────
my-new-alias firstname.lastname@example.org 00D21000000HTDoXXO 2020-10-21
Oct 14, 2020 at 16:40
1,063 12 12 silver badges 17 17 bronze badges
I was able to directly edit ~/.sfdx/alias.json
Oct 22, 2020 at 0:47
163 1 1 gold badge 2 2 silver badges 8 8 bronze badges
I had to also do
sfdx alias:unset blah to remove an alias I didn't want to have in my life
Aug 19, 2021 at 20:33
In bash, using the support of jq, I set up a function like below
* the below function is pointing to "nonScratchOrgs" so it would need to be tweaked if we are looking to change aliases for scratch orgs as well: NOTE
echo What is the **OLD** alias name you would like to replace?
echo What is the **NEW** alias name you would like to set?
org_list=$(sfdx force:org:list --json)
ORIGINAL_USERNAME=$(echo $org_list | jq --arg alias $oldalias -r '.result.nonScratchOrgs | select(.alias == $alias )' | jq -r '.username')
echo sfdx alias:set $NEW_ALIAS=$ORIGINAL_USERNAME --json
time sfdx alias:set $NEW_ALIAS=$ORIGINAL_USERNAME --json
Aug 12, 2022 at 14:24
sfdx alias:unset aliasvalue
as Eugene mentioned,This is the right way.
Setting an empty alias now marks the value as undefined and causes issue.
Sep 8, 2021 at 0:55
log in to answer this question.
Not the answer you're looking for? Browse other questions tagged
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our
Accept all cookies
Necessary cookies only