How Can I Exclude a File from Deploy in gcloud?

When deploying applications using gcloud (such as App Engine, Cloud Functions, or Cloud Run), it’s often necessary to exclude certain files or directories from being uploaded and deployed — for example, test files, local configuration, or large assets not needed in production.

Recommended Approach: Use .gcloudignore

Google Cloud supports a .gcloudignore file, similar to .gitignore, which lets you specify files and directories to exclude from deployment.

Step-by-Step: Using .gcloudignore

  1. Create a .gcloudignore file in the root of your project (same directory where you run the gcloud deploy command).
  2. Add files/directories to exclude using Unix-style wildcard patterns.
  3. # Exclude local secrets
    .env
    secrets.json
    
    # Exclude node_modules folder
    node_modules/
    
    # Exclude test files
    tests/
    *.test.js
    
    # Exclude Docker-related files
    Dockerfile
    docker-compose.yml
  4. The .gcloudignore file will automatically be respected.

Notes

  • If .gcloudignore doesn’t exist, gcloud will fall back to using .gitignore.
  • If neither exists, all files are included in the deployment.

You can verify what’s being uploaded using the –verbosity debug flag:

gcloud app deploy
gcloud functions deploy FUNCTION_NAME --runtime nodejs20 --trigger-http
gcloud run deploy SERVICE_NAME --source=.

Best Practices

  • Always exclude credentials, secrets, and environment-specific files.
  • Exclude large folders like node_modules, .venv, or __pycache__ unless needed.
  • Keep your .gcloudignore under version control so team members also benefit.

Need Help With Cloud Development?

Work with our skilled Cloud developers to accelerate your project and boost its performance.

Hire Cloud Developers

Support On Demand!

Related Q&A