To add one directory to an existing sparse checkout on your Mac, open Terminal, go to the repository root, and run git sparse-checkout add 'path/to/directory'. Git makes tracked files under that directory available in the working tree while keeping the other sparse-checkout selections. If the repository is not already sparse, use git sparse-checkout set --cone 'path/to/directory' to enable cone mode and choose the directory; this sets the selection, so it can remove other tracked files from the working tree.

Before you run the command

Sparse checkout changes which tracked files appear in a repository’s working tree. Files outside the selected area remain tracked by Git; they are not deleted from the repository’s history. In the default cone mode, Git includes everything under a selected directory, plus files immediately inside its parent directories and the repository root. That means adding a nested directory can also make nearby top-level or parent-level files visible. Git’s sparse-checkout manual

Open Terminal and check that Git is available, then move into the repository. For example, replace the sample path with the location of your checkout:

git --version
cd "$HOME/Projects/sample-repo"
git status --short

On a Mac without Git command-line tools installed, invoking git may prompt you to install Apple’s Command Line Tools. Follow the macOS prompt, then run git --version again. Apple: Installing the Command Line Tools

Use git status --short to check for local changes before changing the sparse selection. Keep important uncommitted or untracked work safe, especially if it is inside a directory that may become excluded. Run sparse-checkout commands from within the repository, and use paths relative to its root. Quote paths that contain spaces or shell metacharacters, as in the examples, so zsh or bash passes the path to Git as one argument.

Add a directory to an existing sparse checkout

If sparse checkout is already enabled, add the directory with:

git sparse-checkout add 'Packages/Map View'

Replace Packages/Map View with the directory path as it appears in the repository. In cone mode, this adds that directory to the current selection rather than replacing the other selected directories. Git documents add as requiring an existing sparse checkout; it updates the selection and working tree. Git sparse-checkout command reference

To inspect the selected directories afterward, run:

git sparse-checkout list
git status --short

The list shows the sparse-checkout directories. Status helps you see whether tracked or untracked files are modified; it does not display omitted tracked files as deleted merely because they are outside the sparse selection.

If this is a regular checkout

For a full checkout that you want to convert to a sparse checkout containing a chosen directory, use set:

git sparse-checkout set --cone 'Packages/Map View'

set establishes the sparse selection from the paths you provide. It does not preserve other directories from a regular full checkout as additional selections. If you need several directories, include each one in the same command, for example git sparse-checkout set --cone 'Packages/Map View' 'Docs'. Git sparse-checkout command reference

Changing the selection can remove files from the working tree. Git’s documentation also notes that when changing cone-mode selections it may delete ignored files in directories that no longer have tracked or non-ignored untracked files. Check your status and safeguard any local files you need before running set; if Git warns that untracked files prevent cleanup, inspect those files instead of forcing removal. Git sparse-checkout manual

If Git reports a problem

If git sparse-checkout add says the repository is not in a sparse checkout, choose whether you intend to narrow the working tree. To do so, use the set --cone command above. If you intended to keep all current directories and only add one, first identify the directories you want to retain, then pass all of them and the new directory to set --cone together.

If a path is not present after adding it, confirm the spelling and capitalization against the repository’s tracked paths, and check whether it exists on the current branch. Sparse checkout selects tracked paths; it does not create a missing directory or initialize a submodule automatically. Git documents submodule initialization as a separate operation. Git sparse-checkout manual

Sparse checkout controls which files Git places in the working tree; it is not the same as cloning only a directory or deleting other directories from the repository. Git supports separate partial-clone filters for limiting objects downloaded from a server, but availability and effect depend on the clone and server configuration. The git clone --sparse option starts with top-level files and is another workflow for a new clone. Git clone documentation

Sources