# How actions/checkout Handles Large Repositories: Shallow Clones, Partial Clones, and Sparse Checkout

> Learn how actions/checkout efficiently handles large repositories using shallow clones, partial clones, and sparse checkout to reduce network traffic and disk space.

- Repository: [GitHub Actions/checkout](https://github.com/actions/checkout)
- Tags: deep-dive
- Published: 2026-07-17

---

**TLDR:** The `actions/checkout` action minimizes network traffic and disk usage for large repositories by leveraging shallow clones (`fetch-depth`), partial clones (`filter`), and sparse checkout patterns, with inputs parsed in [`src/input-helper.ts`](https://github.com/actions/checkout/blob/main/src/input-helper.ts) and executed through [`src/git-source-provider.ts`](https://github.com/actions/checkout/blob/main/src/git-source-provider.ts) and [`src/git-command-manager.ts`](https://github.com/actions/checkout/blob/main/src/git-command-manager.ts).

The `actions/checkout` GitHub Action is engineered to efficiently clone massive monorepos and repositories with extensive histories without saturating network bandwidth or CI runner storage. By exposing Git's advanced features as declarative workflow inputs, the action allows you to fetch only the specific commits, objects, and files required for your build. This deep dive examines the implementation in `actions/checkout` that translates these inputs into optimized Git commands.

## Shallow Cloning with fetch-depth

The `fetch-depth` input controls how much commit history the action retrieves. In [`src/input-helper.ts`](https://github.com/actions/checkout/blob/main/src/input-helper.ts), the action parses this value and defaults to `1` when unspecified, creating a shallow clone that contains only the latest commit. Setting `fetch-depth: 0` disables the shallow clone entirely, fetching the complete history along with all branches. This setting is stored in the `IGitSourceSettings` interface defined in [`src/git-source-settings.ts`](https://github.com/actions/checkout/blob/main/src/git-source-settings.ts) and passed to the clone logic in [`src/git-source-provider.ts`](https://github.com/actions/checkout/blob/main/src/git-source-provider.ts).

## Partial Cloning with filter

For repositories containing large binary blobs, the `filter` input enables partial clone capabilities. When provided, the action passes this value directly to `git clone` using the `--filter` flag, as implemented in [`src/git-source-settings.ts`](https://github.com/actions/checkout/blob/main/src/git-source-settings.ts). Common values like `blob:none` instruct Git to download only tree and commit objects initially, fetching blob content on demand during checkout. This significantly reduces the initial repository size transferred to the runner.

## Sparse Checkout for Targeted Directories

The `sparse-checkout` input allows you to check out only specific directories or files rather than the entire working tree. In [`src/input-helper.ts`](https://github.com/actions/checkout/blob/main/src/input-helper.ts), the action reads both `sparse-checkout` and `sparse-checkout-cone-mode` inputs. After the initial clone, [`src/git-directory-helper.ts`](https://github.com/actions/checkout/blob/main/src/git-directory-helper.ts) executes `git sparse-checkout init` followed by `git sparse-checkout set <patterns>` to configure the sparse checkout pattern. When `sparse-checkout-cone-mode` is set to `true`, the action uses cone mode for faster pattern matching; `false` enables the classic sparse-checkout pattern syntax.

## Implementation Architecture

The optimization features are orchestrated across several TypeScript modules:

1. **Input Processing** – The `getInputs()` function in [`src/input-helper.ts`](https://github.com/actions/checkout/blob/main/src/input-helper.ts) reads and validates all user inputs, including `fetchDepth`, `filter`, and `sparseCheckout`, populating an `IGitSourceSettings` object.

2. **Command Construction** – [`src/git-source-provider.ts`](https://github.com/actions/checkout/blob/main/src/git-source-provider.ts) constructs the final `git clone` command by combining settings from `IGitSourceSettings`, appending `--depth` and `--filter` flags where specified.

3. **Execution** – [`src/git-command-manager.ts`](https://github.com/actions/checkout/blob/main/src/git-command-manager.ts) handles the actual Git execution, including retry logic and authentication, running the optimized clone command.

4. **Post-Clone Configuration** – For sparse checkout operations, [`src/git-directory-helper.ts`](https://github.com/actions/checkout/blob/main/src/git-directory-helper.ts) runs additional commands to initialize and set sparse-checkout patterns after the repository exists locally.

## Configuration Examples

```yaml

# Shallow clone (default) - only latest commit

- uses: actions/checkout@v7

# Full history for release notes or versioning

- uses: actions/checkout@v7
  with:
    fetch-depth: 0
    fetch-tags: true

# Partial clone excluding binary blobs

- uses: actions/checkout@v7
  with:
    filter: blob:none
    fetch-depth: 1

# Sparse checkout of src directory only (cone mode)

- uses: actions/checkout@v7
  with:
    sparse-checkout: |
      src/
    sparse-checkout-cone-mode: true

# Sparse checkout specific files (non-cone mode)

- uses: actions/checkout@v7
  with:
    sparse-checkout: |
      README.md
      docs/architecture.md
    sparse-checkout-cone-mode: false

```

## Summary

- **Shallow clones** via `fetch-depth` limit history download (default `1`, set to `0` for full history), parsed in [`src/input-helper.ts`](https://github.com/actions/checkout/blob/main/src/input-helper.ts) and applied in [`src/git-source-provider.ts`](https://github.com/actions/checkout/blob/main/src/git-source-provider.ts).
- **Partial clones** via `filter` exclude large objects (e.g., `blob:none`), configured in [`src/git-source-settings.ts`](https://github.com/actions/checkout/blob/main/src/git-source-settings.ts).
- **Sparse checkout** limits the working directory to specific paths, initialized in [`src/git-directory-helper.ts`](https://github.com/actions/checkout/blob/main/src/git-directory-helper.ts) using patterns from [`src/input-helper.ts`](https://github.com/actions/checkout/blob/main/src/input-helper.ts).
- The execution flow moves from input validation ([`input-helper.ts`](https://github.com/actions/checkout/blob/main/input-helper.ts)) to command construction ([`git-source-provider.ts`](https://github.com/actions/checkout/blob/main/git-source-provider.ts)) to Git execution ([`git-command-manager.ts`](https://github.com/actions/checkout/blob/main/git-command-manager.ts)).

## Frequently Asked Questions

### How does actions/checkout minimize disk usage for large repositories?

The action minimizes disk usage by defaulting to shallow clones (`fetch-depth: 1`), supporting partial clones (`filter`), and enabling sparse checkout patterns. These features are implemented across [`src/input-helper.ts`](https://github.com/actions/checkout/blob/main/src/input-helper.ts), [`src/git-source-settings.ts`](https://github.com/actions/checkout/blob/main/src/git-source-settings.ts), and [`src/git-directory-helper.ts`](https://github.com/actions/checkout/blob/main/src/git-directory-helper.ts) to ensure only necessary data reaches the runner.

### What input controls the shallow clone depth?

The `fetch-depth` input controls shallow cloning, parsed by `getInputs()` in [`src/input-helper.ts`](https://github.com/actions/checkout/blob/main/src/input-helper.ts). A value of `1` creates a shallow clone with only the latest commit, while `0` fetches the complete history.

### Which file handles sparse-checkout configuration?

The [`src/git-directory-helper.ts`](https://github.com/actions/checkout/blob/main/src/git-directory-helper.ts) file handles sparse-checkout setup. After the initial clone, it executes `git sparse-checkout init` and `git sparse-checkout set` using patterns defined by the `sparse-checkout` input read in [`src/input-helper.ts`](https://github.com/actions/checkout/blob/main/src/input-helper.ts).

### How is the git clone command constructed with filters?

The [`src/git-source-provider.ts`](https://github.com/actions/checkout/blob/main/src/git-source-provider.ts) constructs the clone command using settings from `IGitSourceSettings` (defined in [`src/git-source-settings.ts`](https://github.com/actions/checkout/blob/main/src/git-source-settings.ts)), appending `--filter` and `--depth` flags as specified. The [`src/git-command-manager.ts`](https://github.com/actions/checkout/blob/main/src/git-command-manager.ts) then executes this command.