THE GITHTML FIELD GUIDE

Use sparse checkout for selected repository directories

Git sparse-checkout controls which tracked files are present in your working tree. In cone mode, you select directories and Git includes related parent-level files according to its rules. It is not the same as a shallow or partial clone. Use it for a specific large-repository task, not as a requirement for reading GitHub files.

Separate working files from repository data

Sparse checkout reduces the visible working-tree scope. A normal repository can still retain its history and objects even when many tracked paths are not materialized as files. Shallow clone limits ancestry, while partial clone changes which objects are initially downloaded. These mechanisms can be combined deliberately, but they solve different resource problems.

Consider a monorepo where you only work on packages/parser. Sparse checkout may reduce local clutter and checkout work, yet builds can depend on shared configuration or sibling packages. Inventory those dependencies before narrowing the selection. An incomplete working tree can cause tool failures that look like missing source, even though the files remain tracked in the repository.

Start from a safe, understood working state

Inspect status and preserve uncommitted changes before changing sparse selection. The example selects a project directory and shared tools in cone mode. Replace them with real directories that cover your task. The command updates which files are present, so this is not merely a read-only filter in your file browser.

  1. Check representative root and parent-directory files as well as the selected directories; cone mode intentionally includes more than only the named leaves.
  2. Run the project’s relevant checks to identify dependencies outside the selection, then add only the directories actually required for the task.
shell
git status --short
git sparse-checkout set --cone packages/parser tools
git sparse-checkout list
git status --short

Expand or disable without treating omissions as deletions

Use sparse-checkout add when another directory is needed, and sparse-checkout disable when you want the normal full working tree again. Preserve current edits and inspect status around these changes. Do not manually delete tracked paths or commit their absence as a substitute for sparse configuration; Git’s sparse mechanism distinguishes omitted files from intended repository deletions.

The Git manual describes this feature as experimental, so verify behavior with the version installed on your machine and the tools used by the project. Some editors or build systems assume a complete checkout. If the goal is simply browsing a file on GitHub or reading a document in a reader app, sparse checkout adds no necessary capability. Use it when a local development task benefits from a narrower working set and you can explain the selected directories and the dependencies they cover.

Sparse selection is local checkout configuration, not a permission boundary. It does not prevent an authorized user from requesting other repository paths or inspecting their history.

Sources and further reading

AI-assisted writing with source-linked guidance and illustrative examples. Read our editorial approach or report a correction.

All git fundamentals guides →

Read as MarkdownAll guides

Use sparse checkout for selected repository directories · gitHtml