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

> Learn Git sparse checkout to exclude translation files from the microsoft AI-For-Beginners repo. Optimize your downloads by focusing on core content only.

- Repository: [Microsoft/AI-For-Beginners](https://github.com/microsoft/AI-For-Beginners)
- Tags: how-to-guide
- Published: 2026-08-25

---

**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`](https://github.com/microsoft/AI-For-Beginners/blob/main/README.md) [lines 33-47] and mirrored across language-specific READMEs such as [`translations/zh-TW/README.md`](https://github.com/microsoft/AI-For-Beginners/blob/main/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.

```bash
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:

```bash
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:

```bash
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)

```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)

```cmd
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`:

```bash
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:

```bash
git sparse-checkout disable
git checkout

```

## Key Files in the Repository

| File | Purpose |
|------|---------|
| [`README.md`](https://github.com/microsoft/AI-For-Beginners/blob/main/README.md) | Contains the primary sparse-checkout documentation [lines 33-47] |
| [`translations/zh-TW/README.md`](https://github.com/microsoft/AI-For-Beginners/blob/main/translations/zh-TW/README.md) | Traditional Chinese translation with mirrored instructions [lines 36-46] |
| [`translations/vi/README.md`](https://github.com/microsoft/AI-For-Beginners/blob/main/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.