How to Use Git Sparse Checkout to Exclude Translation Files in AI-For-Beginners

Use git clone --filter=blob:none --sparse combined with git sparse-checkout set to download only the core curriculum while omitting the translations and translated_images directories that contain 50+ language localizations.

The microsoft/AI-For-Beginners repository ships with comprehensive translations across more than 50 languages, which significantly increases the total download size. For learners who only need the English curriculum or a specific subset of content, Git's sparse checkout feature provides a built-in mechanism to clone the repository structure without fetching the heavy translation blobs. This technique is documented directly in the repository's README.md [lines 33-47] and mirrored across language-specific READMEs such as translations/zh-TW/README.md [lines 36-46].

How Sparse Checkout Works in AI-For-Beginners

Sparse checkout operates as a three-stage process that delays blob downloads until files are actually needed. This approach is particularly effective for repositories with large, optional content directories.

Stage 1: Clone with Blob Filtering

The --filter=blob:none flag instructs Git to download only tree objects (directory structures) during the initial clone, excluding all file contents (blobs). The --sparse flag simultaneously enables the sparse-checkout feature for the repository.

git clone --filter=blob:none --sparse https://github.com/microsoft/AI-For-Beginners.git

Without this filter, a full clone retrieves every translation file and associated image asset—often totaling several gigabytes that remain unused.

Stage 2: Define Inclusion and Exclusion Patterns

After cloning, the git sparse-checkout set command establishes which paths populate your working tree. The AI-For-Beginners repository recommends this specific pattern set:

cd AI-For-Beginners
git sparse-checkout set --no-cone '/*' '!translations' '!translated_images'

Breaking down the pattern syntax:

  • /* — Includes every top-level path in the repository
  • !translations — Excludes the entire translations/ directory containing all language localizations
  • !translated_images — Excludes the translated_images/ directory containing localized visual assets
  • --no-cone — Disables Git's "cone mode" optimization, ensuring patterns match exactly as written without implicit directory expansion

The --no-cone flag is essential here because the exclusion patterns use leading ! negation, which requires literal interpretation rather than cone-based pattern matching.

Stage 3: Verify the Configuration

Git stores the active sparse-checkout patterns in .git/info/sparse-checkout. You can inspect this file to confirm your rules:

cat .git/info/sparse-checkout

Expected output:


/*
!translations
!translated_images

When you subsequently run git checkout or git pull, Git fetches blobs only for files matching the inclusion patterns. The excluded directories appear as empty paths in your working tree, consuming no local storage.

Platform-Specific Commands

Linux and macOS (Bash)

git clone --filter=blob:none --sparse https://github.com/microsoft/AI-For-Beginners.git
cd AI-For-Beginners
git sparse-checkout set --no-cone '/*' '!translations' '!translated_images'

Windows (Command Prompt)

git clone --filter=blob:none --sparse https://github.com/microsoft/AI-For-Beginners.git
cd AI-For-Beginners
git sparse-checkout set --no-cone "/*" "!translations" "!translated_images"

Note the double quotes in Windows—the shell handles single and double quotes differently than Bash.

Modifying Sparse-Checkout Rules Post-Clone

If you later need additional directories or specific translation files, use git sparse-checkout add:

git sparse-checkout add translations/zh-TW

This fetches the Traditional Chinese translation specifically while maintaining other exclusions. To completely reset and include all files:

git sparse-checkout disable
git checkout

Key Files in the Repository

File Purpose
README.md Contains the primary sparse-checkout documentation [lines 33-47]
translations/zh-TW/README.md Traditional Chinese translation with mirrored instructions [lines 36-46]
translations/vi/README.md Vietnamese translation with identical guidance
.git/info/sparse-checkout Generated configuration file storing active patterns

Summary

  • --filter=blob:none delays all file content downloads until explicitly requested
  • --sparse enables the sparse-checkout feature for path-based filtering
  • --no-cone ensures exact pattern matching for negated exclusion rules
  • The !translations and !translated_images patterns exclude the repository's largest directories
  • Pattern storage in .git/info/sparse-checkout persists across branch checkouts and pulls

Frequently Asked Questions

What Git version supports sparse checkout for AI-For-Beginners?

Sparse checkout with --cone and --no-cone modes requires Git 2.25 or later. The blob filter (--filter=blob:none) requires Git 2.27 or later. Most modern Git installations include these capabilities.

Will sparse checkout break if I need one translation later?

No. Run git sparse-checkout add translations/<language-code> to fetch a specific translation directory on demand. Git downloads only the requested blobs and updates your working tree without re-cloning.

How much storage does sparse checkout actually save?

The AI-For-Beginners repository contains 50+ language translations plus localized image assets. A full clone typically exceeds several gigabytes, while a sparse checkout with translations excluded reduces the initial download to under 100MB—roughly 95% savings depending on the current repository state.

Can I use sparse checkout with sparse index for better performance?

Yes. For repositories with extremely large directory structures, git sparse-checkout init --sparse-index creates a compact index representation. However, for AI-For-Beginners, the standard sparse-checkout configuration provides sufficient performance without additional complexity.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →