You can set gcloud configurations several ways.

With Env Vars

export CLOUDSDK_CORE_PROJECT=apple314

In Configurations

gcloud config set project cherry314

Per Command

--project pumpkin314

Which will win?

We’ve set the env var and default project, now let’s run these commands.

gcloud compute instances list --project pumpkin314
# pumpkin314

gcloud compute instances list
# apple314

unset CLOUDSDK_CORE_PROJECT
gcloud compute instances list
# cherry314

gcloud config unset project
gcloud compute instances list
# sad... no project specified

So the precedence is:

  • –project
  • env var
  • config