Skip to content
← Back to activity

Immutable solution version

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

Version 1Sign in to save

Complete solution

Remote Cloud Build excludes the .git directory from the build context. gcloud's default ignore behavior always excludes .git from the upload tarball, and it does so silently.

The problem

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 fix

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.

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 1 · 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