gcloud

gcloud 480+

Quick reference for gcloud (Google Cloud CLI), gsutil, and bq commands: authentication, project / IAM, Compute / GKE / BigQuery / Cloud Storage, config, and Cloud Build / Deploy — with common options and practical examples.

48 commands

Help

gcloud --version

Print versions of gcloud, gsutil, bq, and the core libraries.

gcloud --version
gcloud help

Show top-level help with the full list of command groups.

gcloud help
gcloud help <cmd>

Show flags + examples for any gcloud command (path separators are spaces).

gcloud help compute instances create
gcloud topic <topic>

Read in-depth docs: `configurations`, `projections`, `filters`, `offline`, etc.

configurations; projections; filters; offline; access-control

gcloud topic filters

Authentication

gcloud init

First-run wizard — login, pick a project, pick a default region / zone.

gcloud init
gcloud auth login

Authorize gcloud to access GCP with your user credentials (browser OAuth flow).

--no-launch-browser; --no-activate

gcloud auth login --no-launch-browser
gcloud auth application-default login

Set up Application Default Credentials — picked up by client libraries (Python / Node / Go).

--scopes <scope1,scope2>; --no-launch-browser

gcloud auth application-default login
gcloud auth activate-service-account --key-file <key.json>

Activate a service account using a downloaded JSON key file.

gcloud auth activate-service-account [email protected] --key-file=ci.json
gcloud auth list

List every credentialed account.

--format=yaml; --filter

gcloud auth list
gcloud auth revoke

Revoke credentials for one account or all.

<account>; --all

gcloud auth revoke --all

Project

gcloud config get-value project

Print the currently active project.

gcloud config get-value project
gcloud config set project <id>

Set the active project.

gcloud config set project my-gcp-project
gcloud projects list

List every project you have access to.

--format='table(projectId,name,projectNumber)'; --limit

gcloud projects list --format='table(projectId,name)'

Configuration

gcloud config configurations list

List every saved configuration (named profile).

--format=yaml

gcloud config configurations list
gcloud config configurations create <name>

Create a new named configuration.

--no-activate

gcloud config configurations create dev --no-activate
gcloud config configurations activate <name>

Switch to an existing configuration.

gcloud config configurations activate prod
CLOUDSDK_ACTIVE_CONFIG_NAME=<name> gcloud ...

Use a configuration without modifying the persistent one (CI / scripts).

CLOUDSDK_ACTIVE_CONFIG_NAME=prod gcloud compute instances list
gcloud config set compute/region <region>

Set a per-property default (region / zone / project / account).

compute/region; compute/zone; container/cluster; compute/region us-central1

gcloud config set compute/region us-central1

Output

gcloud <cmd> --format=<fmt>

Choose output format: `json`, `yaml`, `table`, `csv`, `value`, `default`.

json; yaml; table; csv; value; default; get(<expr>):label

gcloud compute instances list --format='table(name,zone.basename(),machineType.basename())'
gcloud <cmd> --filter='<expr>'

Server-side filter — see `gcloud topic filters` for the expression syntax.

name=foo; zone:us-*; status:RUNNING

gcloud compute instances list --filter='zone:us-central1-a AND labels.env=prod'
gcloud <cmd> --limit <N>

Cap the result count (server-side pagination is unlimited otherwise).

gcloud compute instances list --limit=20

IAM

gcloud iam service-accounts list

List every service account in the active project.

--project; --format=json; --limit

gcloud iam service-accounts list
gcloud iam service-accounts keys create <file.json> --iam-account <sa>

Create a JSON key for a service account — needed by tools that don't support ADC.

--iam-account <sa>; --key-file-type json

gcloud iam service-accounts keys create ci.json --iam-account [email protected]
gcloud projects add-iam-policy-binding <project> --member='user:<email>' --role='roles/<role>'

Grant a role to a member at the project level.

--member=user:foo@bar / serviceAccount:foo / group:bar / domain:bar; --role=roles/owner

gcloud projects add-iam-policy-binding my-proj --member='user:[email protected]' --role='roles/viewer'

Compute Engine

gcloud compute instances list

List every VM with zone, machine type, and status.

--project; --filter; --format=table; --limit

gcloud compute instances list --format='table(name,zone,machineType,status)'
gcloud compute instances create <name> --zone <z> --machine-type <t>

Create a VM with default image (Debian 12).

--zone; --machine-type; --image-family; --image-project; --preemptible; --tags; --labels; --metadata; --service-account; --scopes

gcloud compute instances create vm-dev --zone=us-central1-a --machine-type=e2-medium --image-family=debian-12
gcloud compute ssh <vm> --zone <z>

Open an SSH session to a VM (auto-generates / persists keys under `~/.ssh/google_compute_engine`).

--zone; --ssh-key-file; --command <cmd>; --tunnel-through-iap; --internal-ip

gcloud compute ssh vm-dev --zone=us-central1-a --command 'docker ps'
gcloud compute instances delete <vm> --zone <z>

Delete a VM (with or without disks).

--zone; --delete-disks=all / data / boot

gcloud compute instances delete vm-dev --zone=us-central1-a --delete-disks=all
gcloud compute disks list

List every persistent disk.

--filter='zone:us-*'; --format=table

gcloud compute disks list --format='table(name,sizeGb,zone,status)'
gcloud compute snapshots create <name> --source-disk <disk>

Snapshot a persistent disk for backups or cloning.

--source-disk <name>; --source-disk-zone; --description

gcloud compute snapshots create snap-2026-08-25 --source-disk=data-disk --source-disk-zone=us-central1-a

GKE

gcloud container clusters list

List every GKE cluster.

--region; --format=table; --limit

gcloud container clusters list --format='table(name,zone,masterVersion,status)'
gcloud container clusters get-credentials <name> --region <r>

Merge the cluster's kubeconfig into `~/.kube/config` and switch context.

--region; --zone; --project; --internal-ip

gcloud container clusters get-credentials my-cluster --region=us-central1
gcloud container clusters create <name> --num-nodes=1

Create an Autopilot or Standard GKE cluster.

--num-nodes; --machine-type; --region; --enable-autoscaling; --enable-autorepair; --cluster-version; --release-channel rapid|regular|stable

gcloud container clusters create my-cluster --region=us-central1 --num-nodes=3 --enable-autoscaling --min-nodes=1 --max-nodes=5

Cloud Storage

gsutil ls

List buckets / objects (alias: `gcloud storage ls`).

-r; -l; -h; gs://; -d (list dirs only)

gsutil ls gs://my-bucket/data/
gsutil cp <local> gs://<bucket>/<key>

Upload or copy an object. `-r` for recursive directory copy.

-r; -m parallel; -c preserve cache-control; -p preserve ACL; -n no-clobber; -z <fmt> compress on upload

gsutil cp -r ./dist gs://my-bucket/app/
gsutil rsync -r <src> <dst>

Two-way directory sync (parallel, fast). Source / destination can be local or `gs://`.

-r; -d delete extras; -c checksum-compare; -n dry-run; -x exclude

gsutil rsync -r -d ./build gs://my-bucket/build
gcloud storage buckets create gs://<name> --location <loc>

Create a new Cloud Storage bucket with the specified location / class.

--location; --default-storage-class; --uniform-bucket-level-access; --public-access-prevention

gcloud storage buckets create gs://my-bucket --location=us-central1 --uniform-bucket-level-access

BigQuery

bq query --use_legacy_sql=false 'SELECT ...'

Run an ad-hoc SQL query against BigQuery.

--use_legacy_sql=false; --max_rows; --destination_table; --parameter; --format=json

bq query --use_legacy_sql=false 'SELECT COUNT(*) FROM `bigquery-public-data.samples.shakespeare`'
bq show --format=pretty <project>:<dataset>

Show metadata about a project / dataset / table / job.

--format=pretty; --schema; --view

bq show my-proj:my_dataset
bq load --source_format=CSV --autodetect <dataset>.<table> <file>

Bulk-load a local CSV/JSON/Parquet file into a BigQuery table.

--source_format=CSV|JSON|PARQUET|AVRO|NEWLINE_DELIMITED_JSON; --autodetect; --replace; --skip_leading_rows=1

bq load --source_format=CSV --autodetect --skip_leading_rows=1 my_dataset.users users.csv

Cloud Build

gcloud builds submit --tag gcr.io/<proj>/<img>

Build a container from the current directory using the default Cloud Build config.

--tag; --config <file>; --machine-type; --timeout; --gcs-source-staging-dir; --no-source-image-upload

gcloud builds submit --tag gcr.io/my-proj/app:v1 .

Cloud Deploy

gcloud app deploy <yaml>

Deploy to App Engine standard / flex.

--image-url; --version; --promote; --stop-previous-version

gcloud app deploy app.yaml --promote

Pub/Sub

gcloud pubsub topics publish <topic> --message '<msg>'

Publish a single message — useful for ad-hoc testing.

--message; --attributes; --ordering-key

gcloud pubsub topics publish my-topic --message 'hello' --attributes=k=v
gcloud pubsub subscriptions pull <sub> --limit <N> --auto-ack

Pull (and auto-ack) N messages from a subscription — great for sanity checks.

--limit; --auto-ack; --format=json

gcloud pubsub subscriptions pull my-sub --limit=5 --auto-ack

Deploy / rollback

gcloud components update

Update gcloud itself + every installed component to the latest release.

gcloud components update
gcloud components install <name>

Install an optional gcloud component (kubectl, bq, gsutil, app-engine-python, ...).

<name>

gcloud components install kubectl

Diagnose

gcloud info

Print the gcloud environment: python version, install location, active config.

--run-diagnostics; --log-level=debug

gcloud info
gcloud feedback

Open a browser to the public gcloud issue tracker with environment info pre-filled.

--log-level=debug

gcloud feedback

Related command cheatsheets

About Google Cloud CLI

The Google Cloud CLI (gcloud) is Google's official command-line tool for managing Google Cloud Platform (GCP) services. It bundles three binaries in one installer: `gcloud` (resource management, IAM, App Engine, Cloud SQL, GKE, Compute Engine), `gsutil` (Cloud Storage, originally from the older `gsutil` standalone CLI), and `bq` (BigQuery). The current stable line is gcloud 480+ (Aug 2025 era). gcloud follows the resource-group pattern: `gcloud <group> <resource> <verb>` — e.g. `gcloud compute instances list`, `gcloud iam service-accounts keys create`. Authentication supports interactive `gcloud auth login`, service-account keys, and Application Default Credentials (ADC) via `gcloud auth application-default login` — the latter being the canonical credential source for Terraform, Python, and Node.js SDKs. gcloud is Apache 2.0 licensed and never uploads your code anywhere except via explicit `gcloud app deploy`, `gcloud builds submit`, etc.

Cheatsheet version 1.0.0