How can i change the current running project to another project in GCP (Google Cloud Platform) account using cli commands other than using gcloud init
manually.
$gcloud projects list
will list the projects running on my account. I want to change the current project to any other project from the list using a cli command.
To update your existing project to another project, you can use this command line:
gcloud projects update PROJECT_ID --name=NAME
NAME: will be the new name of your project.
The selected answer doesn't help if you don't know the name of projects you have added gcloud already. My flow is to list the active projects, then switch to the one I want.
gcloud config configurations list
gcloud config configurations activate [NAME]
where [NAME] is listed from the prior command.
You can try: gcloud config set project [project_id]
Make sure you are authenticated with the correct account:
Change to the project's account if not:
Depending on the account, the project list will be different:
Switch to intended project:
Check your project by running gcloud config list Then gcloud config set "project name"
I add aliases to the .bash_alaises to switch to a different project.
Here is a script to generate aliases :) for all projects listed. Please update the switch_proj to unique project aliases that you can remember.