2 .\" Title: git-sparse-checkout
3 .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
7 .\" Source: Git 2.34.1.182.ge773545c7f
10 .TH "GIT\-SPARSE\-CHECKOU" "1" "12/10/2021" "Git 2\&.34\&.1\&.182\&.ge77354" "Git Manual"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 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\&.
35 \fIgit sparse\-checkout <subcommand> [<options>]\fR
40 Initialize and modify the sparse\-checkout configuration, which reduces the checkout to a set of paths given by a list of patterns\&.
42 THIS COMMAND IS EXPERIMENTAL\&. ITS BEHAVIOR, AND THE BEHAVIOR OF OTHER COMMANDS IN THE PRESENCE OF SPARSE\-CHECKOUTS, WILL LIKELY CHANGE IN THE FUTURE\&.
47 Describe the patterns in the sparse\-checkout file\&.
53 \fBcore\&.sparseCheckout\fR
54 setting\&. If the sparse\-checkout file does not exist, then populate it with patterns that match every file in the root directory and no other directories, then will remove all directories tracked by Git\&. Add patterns to the sparse\-checkout file to repopulate the working directory\&.
56 To avoid interfering with other worktrees, it first enables the
57 \fBextensions\&.worktreeConfig\fR
58 setting and makes sure to set the
59 \fBcore\&.sparseCheckout\fR
60 setting in the worktree\-specific config file\&.
65 \fBcore\&.sparseCheckoutCone\fR
66 setting is also set, allowing for better performance with a limited set of patterns (see
67 \fICONE PATTERN SET\fR
71 \fB\-\-[no\-]sparse\-index\fR
72 option to toggle the use of the sparse index format\&. This reduces the size of the index to be more closely aligned with your sparse\-checkout definition\&. This can have significant performance advantages for commands such as
75 \fBgit add\fR\&. This feature is still experimental\&. Some commands might be slower with a sparse index until they are properly integrated with the feature\&.
78 Using a sparse index requires modifying the index in a way that is not completely understood by external tools\&. If you have trouble with this compatibility, then run
79 \fBgit sparse\-checkout init \-\-no\-sparse\-index\fR
80 to rewrite your index to not be sparse\&. Older versions of Git will not understand the sparse directory entries index extension and may fail to interact with your repository until it is disabled\&.
85 Write a set of patterns to the sparse\-checkout file, as given as a list of arguments following the
87 subcommand\&. Update the working directory to match the new patterns\&. Enable the core\&.sparseCheckout config setting if it is not already enabled\&.
91 option is provided, the patterns are read from standard in as a newline\-delimited list instead of from the arguments\&.
94 \fBcore\&.sparseCheckoutCone\fR
95 is enabled, the input list is considered a list of directories instead of sparse\-checkout patterns\&. The command writes patterns to the sparse\-checkout file to include all files contained in those directories (recursively) as well as files that are siblings of ancestor directories\&. The input format matches the output of
96 \fBgit ls\-tree \-\-name\-only\fR\&. This includes interpreting pathnames that begin with a double quote (") as C\-style quoted strings\&.
101 Update the sparse\-checkout file to include additional patterns\&. By default, these patterns are read from the command\-line arguments, but they can be read from stdin using the
104 \fBcore\&.sparseCheckoutCone\fR
105 is enabled, the given patterns are interpreted as directory names as in the
112 Reapply the sparsity pattern rules to paths in the working tree\&. Commands like merge or rebase can materialize paths to do their work (e\&.g\&. in order to show you a conflict), and other sparse\-checkout commands might fail to sparsify an individual file (e\&.g\&. because it has unstaged changes or conflicts)\&. In such cases, it can make sense to run
113 \fBgit sparse\-checkout reapply\fR
114 later after cleaning up affected paths (e\&.g\&. resolving conflicts, undoing or committing changes, etc\&.)\&.
120 \fBcore\&.sparseCheckout\fR
121 config setting, and restore the working directory to include all files\&. Leaves the sparse\-checkout file intact so a later
122 \fIgit sparse\-checkout init\fR
123 command may return the working directory to the same state\&.
125 .SH "SPARSE CHECKOUT"
127 "Sparse checkout" allows populating the working directory sparsely\&. It uses the skip\-worktree bit (see \fBgit-update-index\fR(1)) to tell Git whether a file in the working directory is worth looking at\&. If the skip\-worktree bit is set, then the file is ignored in the working directory\&. Git will not populate the contents of those files, which makes a sparse checkout helpful when working in a repository with many files, but only a few are important to the current user\&.
129 The \fB$GIT_DIR/info/sparse\-checkout\fR file is used to define the skip\-worktree reference bitmap\&. When Git updates the working directory, it updates the skip\-worktree bits in the index based on this file\&. The files matching the patterns in the file will appear in the working directory, and the rest will not\&.
131 To enable the sparse\-checkout feature, run \fBgit sparse\-checkout init\fR to initialize a simple sparse\-checkout file and enable the \fBcore\&.sparseCheckout\fR config setting\&. Then, run \fBgit sparse\-checkout set\fR to modify the patterns in the sparse\-checkout file\&.
133 To repopulate the working directory with all files, use the \fBgit sparse\-checkout disable\fR command\&.
134 .SH "FULL PATTERN SET"
136 By default, the sparse\-checkout file uses the same syntax as \fB\&.gitignore\fR files\&.
138 While \fB$GIT_DIR/info/sparse\-checkout\fR is usually used to specify what files are included, you can also specify what files are \fInot\fR included, using negative patterns\&. For example, to remove the file \fBunwanted\fR:
151 .SH "CONE PATTERN SET"
153 The full pattern set allows for arbitrary pattern matches and complicated inclusion/exclusion rules\&. These can result in O(N*M) pattern matches when updating the index, where N is the number of patterns and M is the number of paths in the index\&. To combat this performance issue, a more restricted pattern set is allowed when \fBcore\&.sparseCheckoutCone\fR is enabled\&.
155 The accepted patterns in the cone pattern set are:
166 All paths inside a directory are included\&.
178 All files immediately inside a directory are included\&.
181 In addition to the above two patterns, we also expect that all files in the root directory are included\&. If a recursive pattern is added, then all leading directories are added as parent patterns\&.
183 By default, when running \fBgit sparse\-checkout init\fR, the root directory is added as a parent pattern\&. At this point, the sparse\-checkout file contains the following patterns:
197 This says "include everything in root, but nothing two levels below root\&."
199 When in cone mode, the \fBgit sparse\-checkout set\fR subcommand takes a list of directories instead of a list of sparse\-checkout patterns\&. In this mode, the command \fBgit sparse\-checkout set A/B/C\fR sets the directory \fBA/B/C\fR as a recursive pattern, the directories \fBA\fR and \fBA/B\fR are added as parent patterns\&. The resulting sparse\-checkout file is now
218 Here, order matters, so the negative patterns are overridden by the positive patterns that appear lower in the file\&.
220 If \fBcore\&.sparseCheckoutCone=true\fR, then Git will parse the sparse\-checkout file expecting patterns of these types\&. Git will warn if the patterns do not match\&. If the patterns do match the expected format, then Git will use faster hash\- based algorithms to compute inclusion in the sparse\-checkout\&.
222 In the cone mode case, the \fBgit sparse\-checkout list\fR subcommand will list the directories that define the recursive patterns\&. For the example sparse\-checkout file above, the output is as follows:
228 $ git sparse\-checkout list
236 If \fBcore\&.ignoreCase=true\fR, then the pattern\-matching algorithm will use a case\-insensitive check\&. This corrects for case mismatched filenames in the \fIgit sparse\-checkout set\fR command to reflect the expected cone in the working directory\&.
238 When changing the sparse\-checkout patterns in cone mode, Git will inspect each tracked directory that is not within the sparse\-checkout cone to see if it contains any untracked files\&. If all of those files are ignored due to the \fB\&.gitignore\fR patterns, then the directory will be deleted\&. If any of the untracked files within that directory is not ignored, then no deletions will occur within that directory and a warning message will appear\&. If these files are important, then reset your sparse\-checkout definition so they are included, use \fBgit add\fR and \fBgit commit\fR to store them, then remove any remaining files manually to ensure Git can behave optimally\&.
241 If your repository contains one or more submodules, then submodules are populated based on interactions with the \fBgit submodule\fR command\&. Specifically, \fBgit submodule init \-\- <path>\fR will ensure the submodule at \fB<path>\fR is present, while \fBgit submodule deinit [\-f] \-\- <path>\fR will remove the files for the submodule at \fB<path>\fR (including any untracked files, uncommitted changes, and unpushed history)\&. Similar to how sparse\-checkout removes files from the working tree but still leaves entries in the index, deinitialized submodules are removed from the working directory but still have an entry in the index\&.
243 Since submodules may have unpushed changes or untracked files, removing them could result in data loss\&. Thus, changing sparse inclusion/exclusion rules will not cause an already checked out submodule to be removed from the working copy\&. Said another way, just as \fBcheckout\fR will not cause submodules to be automatically removed or initialized even when switching between branches that remove or add submodules, using \fBsparse\-checkout\fR to reduce or expand the scope of "interesting" files will not cause submodules to be automatically deinitialized or initialized either\&.
245 Further, the above facts mean that there are multiple reasons that "tracked" files might not be present in the working copy: sparsity pattern application from sparse\-checkout, and submodule initialization state\&. Thus, commands like \fBgit grep\fR that work on tracked files in the working copy may return results that are limited by either or both of these restrictions\&.
248 \fBgit-read-tree\fR(1) \fBgitignore\fR(5)
251 Part of the \fBgit\fR(1) suite