{
    "content": [
        {
            "type": "text",
            "text": "# git-sparse-checkout(1) (man)\n\n**Summary:** git-sparse-checkout - Initialize and modify the sparse-checkout configuration, which reduces the checkout to a set of paths given by a list of patterns.\n\n**Synopsis:** git sparse-checkout <subcommand> [options]\n\n## See Also\n\n- git-read-tree(1)\n- gitignore(5)\n\n## Section Outline\n\n- **NAME** (3 lines)\n- **SYNOPSIS** (3 lines)\n- **DESCRIPTION** (6 lines)\n- **COMMANDS** (62 lines)\n- **SPARSE CHECKOUT** (19 lines)\n- **FULL PATTERN SET** (10 lines)\n- **CONE PATTERN SET** (67 lines)\n- **SUBMODULES** (21 lines)\n- **SEE ALSO** (2 lines)\n- **GIT** (5 lines)\n\n## Full Content\n\n### NAME\n\ngit-sparse-checkout - Initialize and modify the sparse-checkout configuration, which reduces\nthe checkout to a set of paths given by a list of patterns.\n\n### SYNOPSIS\n\ngit sparse-checkout <subcommand> [options]\n\n### DESCRIPTION\n\nInitialize and modify the sparse-checkout configuration, which reduces the checkout to a set\nof paths given by a list of patterns.\n\nTHIS COMMAND IS EXPERIMENTAL. ITS BEHAVIOR, AND THE BEHAVIOR OF OTHER COMMANDS IN THE\nPRESENCE OF SPARSE-CHECKOUTS, WILL LIKELY CHANGE IN THE FUTURE.\n\n### COMMANDS\n\nlist\nDescribe the patterns in the sparse-checkout file.\n\ninit\nEnable the core.sparseCheckout setting. If the sparse-checkout file does not exist, then\npopulate it with patterns that match every file in the root directory and no other\ndirectories, then will remove all directories tracked by Git. Add patterns to the\nsparse-checkout file to repopulate the working directory.\n\nTo avoid interfering with other worktrees, it first enables the extensions.worktreeConfig\nsetting and makes sure to set the core.sparseCheckout setting in the worktree-specific\nconfig file.\n\nWhen --cone is provided, the core.sparseCheckoutCone setting is also set, allowing for\nbetter performance with a limited set of patterns (see CONE PATTERN SET below).\n\nUse the --[no-]sparse-index option to toggle the use of the sparse index format. This\nreduces the size of the index to be more closely aligned with your sparse-checkout\ndefinition. This can have significant performance advantages for commands such as git\nstatus or git add. This feature is still experimental. Some commands might be slower with\na sparse index until they are properly integrated with the feature.\n\nWARNING: Using a sparse index requires modifying the index in a way that is not\ncompletely understood by external tools. If you have trouble with this compatibility,\nthen run git sparse-checkout init --no-sparse-index to rewrite your index to not be\nsparse. Older versions of Git will not understand the sparse directory entries index\nextension and may fail to interact with your repository until it is disabled.\n\nset\nWrite a set of patterns to the sparse-checkout file, as given as a list of arguments\nfollowing the set subcommand. Update the working directory to match the new patterns.\nEnable the core.sparseCheckout config setting if it is not already enabled.\n\nWhen the --stdin option is provided, the patterns are read from standard in as a\nnewline-delimited list instead of from the arguments.\n\nWhen core.sparseCheckoutCone is enabled, the input list is considered a list of\ndirectories instead of sparse-checkout patterns. The command writes patterns to the\nsparse-checkout file to include all files contained in those directories (recursively) as\nwell as files that are siblings of ancestor directories. The input format matches the\noutput of git ls-tree --name-only. This includes interpreting pathnames that begin with a\ndouble quote (\") as C-style quoted strings.\n\nadd\nUpdate the sparse-checkout file to include additional patterns. By default, these\npatterns are read from the command-line arguments, but they can be read from stdin using\nthe --stdin option. When core.sparseCheckoutCone is enabled, the given patterns are\ninterpreted as directory names as in the set subcommand.\n\nreapply\nReapply the sparsity pattern rules to paths in the working tree. Commands like merge or\nrebase can materialize paths to do their work (e.g. in order to show you a conflict), and\nother sparse-checkout commands might fail to sparsify an individual file (e.g. because it\nhas unstaged changes or conflicts). In such cases, it can make sense to run git\nsparse-checkout reapply later after cleaning up affected paths (e.g. resolving conflicts,\nundoing or committing changes, etc.).\n\ndisable\nDisable the core.sparseCheckout config setting, and restore the working directory to\ninclude all files. Leaves the sparse-checkout file intact so a later git sparse-checkout\ninit command may return the working directory to the same state.\n\n### SPARSE CHECKOUT\n\n\"Sparse checkout\" allows populating the working directory sparsely. It uses the skip-worktree\nbit (see git-update-index(1)) to tell Git whether a file in the working directory is worth\nlooking at. If the skip-worktree bit is set, then the file is ignored in the working\ndirectory. Git will not populate the contents of those files, which makes a sparse checkout\nhelpful when working in a repository with many files, but only a few are important to the\ncurrent user.\n\nThe $GITDIR/info/sparse-checkout file is used to define the skip-worktree reference bitmap.\nWhen Git updates the working directory, it updates the skip-worktree bits in the index based\non this file. The files matching the patterns in the file will appear in the working\ndirectory, and the rest will not.\n\nTo enable the sparse-checkout feature, run git sparse-checkout init to initialize a simple\nsparse-checkout file and enable the core.sparseCheckout config setting. Then, run git\nsparse-checkout set to modify the patterns in the sparse-checkout file.\n\nTo repopulate the working directory with all files, use the git sparse-checkout disable\ncommand.\n\n### FULL PATTERN SET\n\nBy default, the sparse-checkout file uses the same syntax as .gitignore files.\n\nWhile $GITDIR/info/sparse-checkout is usually used to specify what files are included, you\ncan also specify what files are not included, using negative patterns. For example, to remove\nthe file unwanted:\n\n/*\n!unwanted\n\n### CONE PATTERN SET\n\nThe full pattern set allows for arbitrary pattern matches and complicated inclusion/exclusion\nrules. These can result in O(N*M) pattern matches when updating the index, where N is the\nnumber of patterns and M is the number of paths in the index. To combat this performance\nissue, a more restricted pattern set is allowed when core.sparseCheckoutCone is enabled.\n\nThe accepted patterns in the cone pattern set are:\n\n1. Recursive: All paths inside a directory are included.\n\n2. Parent: All files immediately inside a directory are included.\n\nIn addition to the above two patterns, we also expect that all files in the root directory\nare included. If a recursive pattern is added, then all leading directories are added as\nparent patterns.\n\nBy default, when running git sparse-checkout init, the root directory is added as a parent\npattern. At this point, the sparse-checkout file contains the following patterns:\n\n/*\n!/*/\n\n\nThis says \"include everything in root, but nothing two levels below root.\"\n\nWhen in cone mode, the git sparse-checkout set subcommand takes a list of directories instead\nof a list of sparse-checkout patterns. In this mode, the command git sparse-checkout set\nA/B/C sets the directory A/B/C as a recursive pattern, the directories A and A/B are added as\nparent patterns. The resulting sparse-checkout file is now\n\n/*\n!/*/\n/A/\n!/A/*/\n/A/B/\n!/A/B/*/\n/A/B/C/\n\n\nHere, order matters, so the negative patterns are overridden by the positive patterns that\nappear lower in the file.\n\nIf core.sparseCheckoutCone=true, then Git will parse the sparse-checkout file expecting\npatterns of these types. Git will warn if the patterns do not match. If the patterns do match\nthe expected format, then Git will use faster hash- based algorithms to compute inclusion in\nthe sparse-checkout.\n\nIn the cone mode case, the git sparse-checkout list subcommand will list the directories that\ndefine the recursive patterns. For the example sparse-checkout file above, the output is as\nfollows:\n\n$ git sparse-checkout list\nA/B/C\n\n\nIf core.ignoreCase=true, then the pattern-matching algorithm will use a case-insensitive\ncheck. This corrects for case mismatched filenames in the git sparse-checkout set command to\nreflect the expected cone in the working directory.\n\nWhen changing the sparse-checkout patterns in cone mode, Git will inspect each tracked\ndirectory that is not within the sparse-checkout cone to see if it contains any untracked\nfiles. If all of those files are ignored due to the .gitignore patterns, then the directory\nwill be deleted. If any of the untracked files within that directory is not ignored, then no\ndeletions will occur within that directory and a warning message will appear. If these files\nare important, then reset your sparse-checkout definition so they are included, use git add\nand git commit to store them, then remove any remaining files manually to ensure Git can\nbehave optimally.\n\n### SUBMODULES\n\nIf your repository contains one or more submodules, then submodules are populated based on\ninteractions with the git submodule command. Specifically, git submodule init -- <path> will\nensure the submodule at <path> is present, while git submodule deinit [-f] -- <path> will\nremove the files for the submodule at <path> (including any untracked files, uncommitted\nchanges, and unpushed history). Similar to how sparse-checkout removes files from the working\ntree but still leaves entries in the index, deinitialized submodules are removed from the\nworking directory but still have an entry in the index.\n\nSince submodules may have unpushed changes or untracked files, removing them could result in\ndata loss. Thus, changing sparse inclusion/exclusion rules will not cause an already checked\nout submodule to be removed from the working copy. Said another way, just as checkout will\nnot cause submodules to be automatically removed or initialized even when switching between\nbranches that remove or add submodules, using sparse-checkout to reduce or expand the scope\nof \"interesting\" files will not cause submodules to be automatically deinitialized or\ninitialized either.\n\nFurther, the above facts mean that there are multiple reasons that \"tracked\" files might not\nbe present in the working copy: sparsity pattern application from sparse-checkout, and\nsubmodule initialization state. Thus, commands like git grep that work on tracked files in\nthe working copy may return results that are limited by either or both of these restrictions.\n\n### SEE ALSO\n\ngit-read-tree(1) gitignore(5)\n\n### GIT\n\nPart of the git(1) suite\n\n\n\nGit 2.34.1                                   02/26/2026                        GIT-SPARSE-CHECKOU(1)\n\n"
        }
    ],
    "structuredContent": {
        "command": "git-sparse-checkout",
        "section": "1",
        "mode": "man",
        "summary": "git-sparse-checkout - Initialize and modify the sparse-checkout configuration, which reduces the checkout to a set of paths given by a list of patterns.",
        "synopsis": "git sparse-checkout <subcommand> [options]",
        "flags": [],
        "examples": [],
        "see_also": [
            {
                "name": "git-read-tree",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/git-read-tree/1/json"
            },
            {
                "name": "gitignore",
                "section": "5",
                "url": "https://www.chedong.com/phpMan.php/man/gitignore/5/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "COMMANDS",
                "lines": 62,
                "subsections": []
            },
            {
                "name": "SPARSE CHECKOUT",
                "lines": 19,
                "subsections": []
            },
            {
                "name": "FULL PATTERN SET",
                "lines": 10,
                "subsections": []
            },
            {
                "name": "CONE PATTERN SET",
                "lines": 67,
                "subsections": []
            },
            {
                "name": "SUBMODULES",
                "lines": 21,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "GIT",
                "lines": 5,
                "subsections": []
            }
        ]
    }
}