gcloud Cheat Sheet
Practical gcloud cheat sheet with setup steps, core workflows, debugging, and copy-paste examples.
gcloud google-cloud cli cloud infrastructure
gcloud cheat sheet with real commands and snippets for setup, core workflows, debugging, and production-safe automation patterns. If you are working across tools, pair this with the AWS CLI Cheat Sheet and Firebase Cheat Sheet.
Setup and Installation
Goal: Verify installation and CLI metadata
# Resolve command path from current shell
command -v gcloud
# Print installed version to confirm runtime
gcloud --version
# Read top-level help before using subcommands
gcloud --help
Goal: Install or upgrade the tool on a workstation
# Install package with Homebrew on macOS
brew install google-cloud-sdk
# Upgrade to the latest available package
brew upgrade google-cloud-sdk
# Re-check version after upgrade
gcloud --version
Goal: Run day-to-day commands
# Authenticate with Google Cloud
gcloud auth login
# List available projects
gcloud projects list
# Set active project for commands
gcloud config set project my-project-id
# Show current identity and project
gcloud config list
Core Workflows
Goal: Capture command help for quick offline lookup
# Create docs folder for generated command references
mkdir -p docs/cli
# Write help output to a timestamped file
gcloud --help > docs/cli/gcloud-help.txt
# Search help output for a keyword
rg "config|auth|deploy" docs/cli/gcloud-help.txt
Goal: Wrap repetitive commands in a script
# Create scripts directory for local automation
mkdir -p scripts
# Write repeatable health-check script
cat > scripts/check-gcloud.sh <<'SH'
#!/usr/bin/env bash
set -euo pipefail
gcloud --version
gcloud --help >/dev/null
SH
# Make script executable and run it
chmod +x scripts/check-gcloud.sh && ./scripts/check-gcloud.sh
Configuration and Environment
Goal: Pin environment variables for predictable runs
# Define environment profile for local commands
export GCLOUD_PROFILE=dev
# Persist profile in local shell configuration
echo 'export GCLOUD_PROFILE=dev' >> ~/.zshrc
# Reload shell profile changes
source ~/.zshrc
Automation and CI
Goal: Add tool checks to CI pipeline
# Run lint/test/build in strict mode
set -euo pipefail
# Verify CLI exists before invoking workflow
command -v gcloud
# Exit quickly if command is unavailable
gcloud --version
Debugging and Troubleshooting
Goal: Collect diagnostics when commands fail
# Capture command output and exit code
gcloud --help > /tmp/gcloud-debug.log 2>&1; echo $?
# Inspect captured diagnostics
tail -n 80 /tmp/gcloud-debug.log
# Check current shell PATH entries
echo $PATH | tr ':' '\n'
Common Gotchas
- Pin gcloud versions in CI so local and pipeline behavior match.
- Check tool authentication context before running write or deploy commands.
- Prefer non-interactive flags in scripts to avoid stalled jobs.
- Capture stderr logs in CI artifacts for faster incident triage.
- Keep secrets in environment variables, not committed scripts.
Related Sheets
- AWS CLI Cheat Sheet — daily AWS CLI commands and production-ready examples.
- Firebase Cheat Sheet — daily Firebase commands and production-ready examples.
- Supabase Cheat Sheet — daily Supabase commands and production-ready examples.
Related Cheat Sheets
AWS CLI Cheat Sheet
Practical AWS CLI cheat sheet with setup steps, core workflows, debugging, and copy-paste examples.
Firebase Cheat Sheet
Practical Firebase cheat sheet with setup steps, core workflows, debugging, and copy-paste examples.
Supabase Cheat Sheet
Practical Supabase cheat sheet with setup steps, core workflows, debugging, and copy-paste examples.