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

> Discover how actions/checkout efficiently handles large repositories using shallow clones partial clones and sparse checkout to minimize network traffic and disk usage for your workflows.

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

---

**actions/checkout minimizes network traffic and disk usage for massive repositories by defaulting to shallow clones while supporting partial clones and sparse checkout patterns to fetch only the history and files your workflow actually requires.**

The `actions/checkout` GitHub Action is engineered to optimize CI/CD performance for repositories of any size. According to the source code in the `actions/checkout` repository, the action combines **shallow cloning**, **partial cloning**, and **sparse checkout** to reduce the amount of data transferred and stored during the checkout process.

## Shallow Clones with fetch-depth

The action implements shallow cloning through the `fetch-depth` input parameter parsed in [[`src/input-helper.ts`](https://github.com/actions/checkout/blob/main/src/input-helper.ts)](https://github.com/actions/checkout/blob/main/src/input-helper.ts). When you do not specify a value, the action defaults to a depth of `1`, which retrieves only the most recent commit and significantly reduces download size for large repositories.

Setting `fetch-depth: 0` disables the shallow clone entirely, fetching the complete history including all commits and tags. This parameter 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)](https://github.com/actions/checkout/blob/main/src/git-source-settings.ts) and passed to the Git command builder.

## Partial Clones with filter

For repositories containing large binary files, the action supports partial cloning via the `filter` input. This parameter is passed directly to the underlying `git clone` command as implemented in [[`src/git-source-settings.ts`](https://github.com/actions/checkout/blob/main/src/git-source-settings.ts)](https://github.com/actions/checkout/blob/main/src/git-source-settings.ts).

Common values include `blob:none` to exclude all blobs or `tree:0` to exclude trees, allowing you to download only the objects necessary for your checkout. The `GitSourceProvider` class in [[`src/git-source-provider.ts`](https://github.com/actions/checkout/blob/main/src/git-source-provider.ts)](https://github.com/actions/checkout/blob/main/src/git-source-provider.ts) constructs the final command string incorporating the `--filter` flag when specified.

## Sparse Checkout for Directory-Specific Workflows

**Sparse checkout** functionality allows workflows to check out only specific directories or files rather than the entire repository tree. The `sparse-checkout` and `sparse-checkout-cone-mode` inputs are parsed in [[`src/input-helper.ts`](https://github.com/actions/checkout/blob/main/src/input-helper.ts)](https://github.com/actions/checkout/blob/main/src/input-helper.ts) and applied through [[`src/git-directory-helper.ts`](https://github.com/actions/checkout/blob/main/src/git-directory-helper.ts)](https://github.com/actions/checkout/blob/main/src/git-directory-helper.ts).

When enabled, the action executes `git sparse-checkout init` followed by `git sparse-checkout set <patterns>` to limit the working tree to specified paths. By default, the action uses cone mode for performance, which restricts patterns to directory-level matches.

## Implementation Architecture

The checkout process follows a structured execution flow across several source files to handle large repositories efficiently.

### Input Processing and Command Construction

First, `getInputs()` in [[`src/input-helper.ts`](https://github.com/actions/checkout/blob/main/src/input-helper.ts)](https://github.com/actions/checkout/blob/main/src/input-helper.ts) constructs an `IGitSourceSettings` object containing all user inputs including `fetchDepth`, `filter`, and `sparseCheckout`. The `GitSourceProvider` class in [[`src/git-source-provider.ts`](https://github.com/actions/checkout/blob/main/src/git-source-provider.ts)](https://github.com/actions/checkout/blob/main/src/git-source-provider.ts) then assembles the final `git clone` command string, incorporating `--depth` and `--filter` flags when specified.

Finally, `GitCommandManager` in [[`src/git-command-manager.ts`](https://github.com/actions/checkout/blob/main/src/git-command-manager.ts)](https://github.com/actions/checkout/blob/main/src/git-command-manager.ts) executes these commands with built-in retry logic and authentication handling.

### Post-Clone Sparse Checkout Setup

After the initial clone completes, the action handles sparse checkout configuration separately. The [[`src/git-directory-helper.ts`](https://github.com/actions/checkout/blob/main/src/git-directory-helper.ts)](https://github.com/actions/checkout/blob/main/src/git-directory-helper.ts) file manages the transition from a full clone to a sparse working tree by executing the necessary Git sparse-checkout commands based on the patterns provided in your workflow configuration.

## Configuration Examples for Large Repositories

The following workflow examples demonstrate how to optimize checkout performance for large repositories:

```yaml

# Example 1: Shallow clone (default behavior)

- uses: actions/checkout@v4

```

```yaml

# Example 2: Full history for release workflows

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

```

```yaml

# Example 3: Partial clone excluding blobs

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

```

```yaml

# Example 4: Sparse checkout of specific directories

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

```

```yaml

# Example 5: Sparse checkout with specific files (non-cone mode)

- uses: actions/checkout@v4
  with:
    sparse-checkout: |
      README.md
      config/ci.yml
    sparse-checkout-cone-mode: false

```

## Summary

- **Shallow clones** default to `fetch-depth: 1` to download only the latest commit, configurable via [[`src/input-helper.ts`](https://github.com/actions/checkout/blob/main/src/input-helper.ts)](https://github.com/actions/checkout/blob/main/src/input-helper.ts).
- **Partial clones** use the `filter` parameter to exclude large objects, implemented in [[`src/git-source-settings.ts`](https://github.com/actions/checkout/blob/main/src/git-source-settings.ts)](https://github.com/actions/checkout/blob/main/src/git-source-settings.ts).
- **Sparse checkout** limits the working tree to specific paths using [[`src/git-directory-helper.ts`](https://github.com/actions/checkout/blob/main/src/git-directory-helper.ts)](https://github.com/actions/checkout/blob/main/src/git-directory-helper.ts) and [[`src/input-helper.ts`](https://github.com/actions/checkout/blob/main/src/input-helper.ts)](https://github.com/actions/checkout/blob/main/src/input-helper.ts).
- The execution flow moves from input parsing (`getInputs()`) to command construction (`GitSourceProvider`) to execution (`GitCommandManager`).
- Combining these features allows workflows to minimize network traffic and disk usage for multi-gigabyte repositories.

## Frequently Asked Questions

### How do I fetch the complete history for a large repository?

Set `fetch-depth: 0` in your workflow configuration. According to [[`src/input-helper.ts`](https://github.com/actions/checkout/blob/main/src/input-helper.ts)](https://github.com/actions/checkout/blob/main/src/input-helper.ts), this value disables the shallow clone and retrieves the full commit history.

### What is the difference between partial clone and sparse checkout?

**Partial clone** uses Git's `--filter` option to exclude specific object types (like blobs) from the download, while **sparse checkout** uses the `sparse-checkout` feature to limit which files appear in your working directory. You can combine both features to minimize both network transfer and local disk usage.

### Can I use sparse checkout with wildcard patterns?

Yes, but the pattern behavior depends on the `sparse-checkout-cone-mode` setting. When set to `true` (the default), patterns must match directories. When set to `false`, you can use specific file paths and wildcards as supported by Git's sparse-checkout command in [[`src/git-directory-helper.ts`](https://github.com/actions/checkout/blob/main/src/git-directory-helper.ts)](https://github.com/actions/checkout/blob/main/src/git-directory-helper.ts).

### Why does actions/checkout default to shallow clones?

The default `fetch-depth: 1` minimizes CI execution time and bandwidth usage for typical workflows that only need the latest code to build and test. You can override this in [[`src/input-helper.ts`](https://github.com/actions/checkout/blob/main/src/input-helper.ts)](https://github.com/actions/checkout/blob/main/src/input-helper.ts) by setting the input to `0` or any specific commit depth your workflow requires.