gcloud CLI Cheat Sheet: Auth, Configurations, Cloud Run, Logging, --format and --filter
Checked against Google Cloud CLI (gcloud) Google Cloud CLI 594.0.1 (21 Nov 2026) on 28 November 2026. Each section links to the official docs it was checked against.
This sheet is for developers who use gcloud for day-to-day Google Cloud work rather than for one-off setup. It tracks the gcloud reference and release notes as of 28 Nov 2026, when the latest release was 594.0.1. gcloud is not installed in my test shell, so the rows come from the reference pages and are marked untested.
When to use what
Keep two kinds of credentials straight. gcloud auth login signs in the CLI itself. gcloud auth application-default login writes Application Default Credentials for your code and client libraries, and its reference says it does not touch the accounts gcloud uses. Most "works in the terminal, fails in my app" problems come from having one and not the other.
Use named configurations instead of running gcloud config set project back and forth. Make one per project or account, then switch with activate, or pass --configuration for a single command. In scripts, set CLOUDSDK_ACTIVE_CONFIG_NAME so the script cannot inherit whatever you last activated by hand.
For output, --format is the tool you want in scripts: value(...) gives bare values for shell variables, csv(...) and json feed other tools, and table(...) with box and sort is for reading. Pair it with --filter to cut rows; logic words must be uppercase and mixed AND/OR needs parentheses.
For Cloud Run, --update-env-vars is usually what you mean; --set-env-vars replaces the full set. If an AI agent will run these commands, see the GCP MCP server and the Cloud Run MCP server, plus our post on MCP servers for cloud infrastructure. The YAML validator helps with service YAML before you deploy it.
gcloud auth loginBrowser sign-in for your user account; sets it active in the current configuration
gcloud auth login --no-launch-browserPrint a URL to open elsewhere and paste the code back
gcloud auth login --update-adcAlso write the credentials to the Application Default Credentials location
gcloud auth application-default loginCreate ADC for local code and client libraries; does not change gcloud's own accounts
Source: https://docs.cloud.google.com/sdk/gcloud/reference/auth/application-default/login
gcloud auth listShow which accounts have credentials and which is active
You can't delete the active configuration; activate another one first.
gcloud config configurations create stagingCreate a named configuration; activate it before use
gcloud config configurations activate stagingSwitch every following command to that configuration
gcloud config configurations listList configurations and see which one is active
gcloud config set project my-projectSet the default project in the active configuration
gcloud config set compute/region us-central1Set the default region for compute commands
gcloud config listPrint the active configuration's properties
gcloud auth list --configuration=stagingUse another configuration for one command only
export CLOUDSDK_ACTIVE_CONFIG_NAME=stagingPin a configuration for the whole shell session or script
gcloud projects list --sort-by=projectId --limit=5First five projects sorted by ID
Source: https://docs.cloud.google.com/sdk/gcloud/reference/projects/list
gcloud projects list --filter='lifecycleState:DELETE_REQUESTED'Projects pending deletion
Source: https://docs.cloud.google.com/sdk/gcloud/reference/projects/list
gcloud compute instances listAll VMs in the project as a table
gcloud compute instances list --zones=us-central1-aOnly VMs in the given zones
gcloud compute instances list --uriPrint each VM's resource URI instead of a table
gcloud compute ssh example-instance --zone=us-central1-aSSH to a VM; gcloud handles keys and resolves the address
Source: https://docs.cloud.google.com/sdk/gcloud/reference/compute/ssh
gcloud compute ssh example-instance --zone=us-central1-a --tunnel-through-iapConnect through Identity-Aware Proxy instead of a public IP; not combinable with --internal-ip
Source: https://docs.cloud.google.com/sdk/gcloud/reference/compute/ssh
gcloud run deploy my-backend --image=us-docker.pkg.dev/project/imageDeploy a prebuilt image to a service
gcloud run deploy my-backend --source .Build from the local folder and deploy
--region=us-central1Region the service runs in
--allow-unauthenticatedAllow public access; --no-allow-unauthenticated turns it off
--update-env-vars=KEY=VALUEAdd or change variables and keep the rest
--set-env-vars=KEY=VALUEReplace the entire set of environment variables
--set-secrets=DB_PASS=db-pass:latestMap secrets to env vars; values use NAME:VERSION
--no-traffic --tag=canaryDeploy a revision that gets no traffic, reachable by its tag
--min-instances=1 --max-instances=10Per-revision instance bounds; --min sets a service-wide minimum
Filter operators: =, !=, : (pattern), ~ and !~ (regex), < <= >= >, and uppercase NOT, AND, OR. Source: https://docs.cloud.google.com/sdk/gcloud/reference/topic/filters
gcloud logging read "severity>=ERROR" --limit=10Newest error entries first; default window is the last day (--freshness=1d)
Source: https://docs.cloud.google.com/sdk/gcloud/reference/logging/read
gcloud logging read "resource.type=gce_instance" --format=jsonFull log entries as JSON for jq or a file
Source: https://docs.cloud.google.com/sdk/gcloud/reference/logging/read
--format="value(config.account)"Print a bare value, handy for shell variables
--format="table[box,title=Instances](name:sort=1, zone:label=zone, status)"Boxed table with a title, sorted by name, with a relabelled column
--format="csv(quotas.metric,quotas.limit,quotas.usage)"CSV of nested fields
--filter="zone ~ us AND -machineType:f1-micro"Regex match on zone and exclude a machine type
Source: https://docs.cloud.google.com/sdk/gcloud/reference/topic/filters
--filter="labels.my-label:*"Rows where the label exists at all
Source: https://docs.cloud.google.com/sdk/gcloud/reference/topic/filters
Worked example: Ship a Cloud Run revision as a canary, then check its errors
You want a new build live under a tag without moving user traffic, using a dedicated staging configuration so nothing lands in production by accident.
gcloud config configurations create staging
gcloud config configurations activate staging
gcloud config set project my-staging-project
gcloud run deploy my-backend \
--image=us-docker.pkg.dev/project/image \
--region=us-central1 \
--update-env-vars=FEATURE_X=on \
--no-traffic --tag=canary
gcloud logging read "severity>=ERROR" --limit=10 --format=json
I couldn't run gcloud here, so this is what to expect rather than real output. After the deploy, gcloud reports the new revision and a URL for the canary tag; the main service URL still serves the previous revision because of --no-traffic. --update-env-vars adds FEATURE_X and leaves the existing variables alone, which --set-env-vars would not.
The last command prints up to ten error entries from the past day, newest first. Narrow it to this service by adding a resource filter (the logging read page shows the resource.type=... form), then check the entries mention the new revision name. If the list is empty, that is the result you wanted.
Common mistakes
Running
gcloud auth loginand expecting your Python or Node code to pick up the same credentials.Client libraries read Application Default Credentials. Run
gcloud auth application-default login, or use--update-adcon login.Using
--set-env-varsto change one variable on a running Cloud Run service.It replaces every variable. Use
--update-env-varsfor a single change.Writing filters with lowercase
andor mixing AND and OR without parentheses.The filters topic requires uppercase logic words and parentheses when AND and OR are combined.
Switching projects with
gcloud config set projectin a shared shell script.Use a named configuration and set
CLOUDSDK_ACTIVE_CONFIG_NAMEor pass--configurationso the script is explicit.Parsing the default table output in scripts.
Use
--format=jsonor--format="value(field)"; table layout is for people and can change.
Related cheat sheets
Sources
- https://docs.cloud.google.com/sdk/docs/configurations
- https://docs.cloud.google.com/sdk/gcloud/reference/auth/login
- https://docs.cloud.google.com/sdk/gcloud/reference/auth/application-default/login
- https://docs.cloud.google.com/sdk/gcloud/reference/run/deploy
- https://docs.cloud.google.com/sdk/gcloud/reference/logging/read
- https://docs.cloud.google.com/sdk/gcloud/reference/topic/formats
- https://docs.cloud.google.com/sdk/gcloud/reference/topic/filters
- https://docs.cloud.google.com/sdk/gcloud/reference/compute/ssh
- https://docs.cloud.google.com/sdk/gcloud/reference/compute/instances/list
- https://docs.cloud.google.com/sdk/gcloud/reference/projects/list
- https://docs.cloud.google.com/sdk/docs/release-notes
How we research: where our facts come from, how often we re-check them, and why no one can pay for a review or a verdict.