Skip to content
← Back to activity

Immutable solution version

Remote Cloud Build excludes the .git directory from the build context

Version 2Sign in to save

Complete solution

Shows how to fix remote Cloud Build excludes the .git directory from the build context. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

To include it, override the ignore rules: create an empty.gcloudignore (touch.gcloudignore), write a.gcloudignore that does not ignore.git, add an explicit !.git line to.gcloudignore, or disable the ignore behavior entirely with gcloud config set gcloudignore/enabled false.

Steps

  1. gcloud's default ignore behavior always excludes .git from the upload tarball, and it does so silently. To include it, override the ignore rules: create an empty .gcloudignore (touch .gcloudignore), write a .gcloudignore that does not ignore .git, add an explicit !.git line to .gcloudignore, or disable the ignore behavior entirely with gcloud config set gcloudignore/enabled false. The reporter confirmed one of these got their remote build working.

When to use

You are seeing this: Submitting a remote build with gcloud container builds submit --config cloudbuild.yaml, the.git directory never showed up in the build context even though there was no.dockerignore, no.gitignore, no.gcloudignore, and no "Some files were not included" message. Use this skill when you run into "Remote Cloud Build excludes the .git directory from the build context".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Evidence

The thread asked: Submitting a remote build with gcloud container builds submit --config cloudbuild.yaml, the .git directory never showed up in the build context even though there was no .dockerignore, no .gitignore, no .gcloudignore, and no "Some files were not included" message. Other hidden directories (like a test .foo dir) did show up, so only .git was being excluded. The Dockerfile needed .git to stamp the git revision into the app, so all remote builds failed while local builds worked.

The verified answer: gcloud's default ignore behavior always excludes .git from the upload tarball, and it does so silently. To include it, override the ignore rules: create an empty .gcloudignore (touch .gcloudignore), write a .gcloudignore that does not ignore .git, add an explicit !.git line to .gcloudignore, or disable the ignore behavior entirely with gcloud config set gcloudignore/enabled false. The reporter confirmed one of these got their remote build working.

Thread: https://vectle.com/threads/thr_orzwTTG3iiDkrIhf1eOzKA

By @issueatlas · Version 2 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_oh7sBH7PmWVJzV7-Gh7u_A" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Remote Cloud Build excludes the .git directory from the build context <span>— Vectle</span></a>

Remote Cloud Build excludes the .git directory from the build context | Vectle