1GIT-SPARSE-CHECKOU(1)             Git Manual             GIT-SPARSE-CHECKOU(1)
2
3
4

NAME

6       git-sparse-checkout - Reduce your working tree to a subset of tracked
7       files
8

SYNOPSIS

10       git sparse-checkout <subcommand> [<options>]
11

DESCRIPTION

13       This command is used to create sparse checkouts, which means that it
14       changes the working tree from having all tracked files present, to only
15       have a subset of them. It can also switch which subset of files are
16       present, or undo and go back to having all tracked files present in the
17       working copy.
18
19       The subset of files is chosen by providing a list of directories in
20       cone mode (which is recommended), or by providing a list of patterns in
21       non-cone mode.
22
23       When in a sparse-checkout, other Git commands behave a bit differently.
24       For example, switching branches will not update paths outside the
25       sparse-checkout directories/patterns, and git commit -a will not record
26       paths outside the sparse-checkout directories/patterns as deleted.
27
28       THIS COMMAND IS EXPERIMENTAL. ITS BEHAVIOR, AND THE BEHAVIOR OF OTHER
29       COMMANDS IN THE PRESENCE OF SPARSE-CHECKOUTS, WILL LIKELY CHANGE IN THE
30       FUTURE.
31

COMMANDS

33       list
34           Describe the directories or patterns in the sparse-checkout file.
35
36       set
37           Enable the necessary sparse-checkout config settings
38           (core.sparseCheckout, core.sparseCheckoutCone, and index.sparse) if
39           they are not already set to the desired values, and write a set of
40           patterns to the sparse-checkout file from the list of arguments
41           following the set subcommand. Update the working directory to match
42           the new patterns.
43
44           To ensure that adjusting the sparse-checkout settings within a
45           worktree does not alter the sparse-checkout settings in other
46           worktrees, the set subcommand will upgrade your repository config
47           to use worktree-specific config if not already present. The
48           sparsity defined by the arguments to the set subcommand are stored
49           in the worktree-specific sparse-checkout file. See git-worktree(1)
50           and the documentation of extensions.worktreeConfig in git-config(1)
51           for more details.
52
53           When the --stdin option is provided, the directories or patterns
54           are read from standard in as a newline-delimited list instead of
55           from the arguments.
56
57           When --cone is passed or core.sparseCheckoutCone is enabled, the
58           input list is considered a list of directories. This allows for
59           better performance with a limited set of patterns (see CONE PATTERN
60           SET below). The input format matches the output of git ls-tree
61           --name-only. This includes interpreting pathnames that begin with a
62           double quote (") as C-style quoted strings. Note that the set
63           command will write patterns to the sparse-checkout file to include
64           all files contained in those directories (recursively) as well as
65           files that are siblings of ancestor directories. This may become
66           the default in the future; --no-cone can be passed to request
67           non-cone mode.
68
69           When --no-cone is passed or core.sparseCheckoutCone is not enabled,
70           the input list is considered a list of patterns. This mode is
71           harder to use and less performant, and is thus not recommended. See
72           the "Sparse Checkout" section of git-read-tree(1) and the "Pattern
73           Set" sections below for more details.
74
75           Use the --[no-]sparse-index option to use a sparse index (the
76           default is to not use it). A sparse index reduces the size of the
77           index to be more closely aligned with your sparse-checkout
78           definition. This can have significant performance advantages for
79           commands such as git status or git add. This feature is still
80           experimental. Some commands might be slower with a sparse index
81           until they are properly integrated with the feature.
82
83           WARNING: Using a sparse index requires modifying the index in a way
84           that is not completely understood by external tools. If you have
85           trouble with this compatibility, then run git sparse-checkout init
86           --no-sparse-index to rewrite your index to not be sparse. Older
87           versions of Git will not understand the sparse directory entries
88           index extension and may fail to interact with your repository until
89           it is disabled.
90
91       add
92           Update the sparse-checkout file to include additional directories
93           (in cone mode) or patterns (in non-cone mode). By default, these
94           directories or patterns are read from the command-line arguments,
95           but they can be read from stdin using the --stdin option.
96
97       reapply
98           Reapply the sparsity pattern rules to paths in the working tree.
99           Commands like merge or rebase can materialize paths to do their
100           work (e.g. in order to show you a conflict), and other
101           sparse-checkout commands might fail to sparsify an individual file
102           (e.g. because it has unstaged changes or conflicts). In such cases,
103           it can make sense to run git sparse-checkout reapply later after
104           cleaning up affected paths (e.g. resolving conflicts, undoing or
105           committing changes, etc.).
106
107           The reapply command can also take --[no-]cone and
108           --[no-]sparse-index flags, with the same meaning as the flags from
109           the set command, in order to change which sparsity mode you are
110           using without needing to also respecify all sparsity paths.
111
112       disable
113           Disable the core.sparseCheckout config setting, and restore the
114           working directory to include all files.
115
116       init
117           Deprecated command that behaves like set with no specified paths.
118           May be removed in the future.
119
120           Historically, set did not handle all the necessary config settings,
121           which meant that both init and set had to be called. Invoking both
122           meant the init step would first remove nearly all tracked files
123           (and in cone mode, ignored files too), then the set step would add
124           many of the tracked files (but not ignored files) back. In addition
125           to the lost files, the performance and UI of this combination was
126           poor.
127
128           Also, historically, init would not actually initialize the
129           sparse-checkout file if it already existed. This meant it was
130           possible to return to a sparse-checkout without remembering which
131           paths to pass to a subsequent set or add command. However, --cone
132           and --sparse-index options would not be remembered across the
133           disable command, so the easy restore of calling a plain init
134           decreased in utility.
135

SPARSE CHECKOUT

137       "Sparse checkout" allows populating the working directory sparsely. It
138       uses the skip-worktree bit (see git-update-index(1)) to tell Git
139       whether a file in the working directory is worth looking at. If the
140       skip-worktree bit is set, and the file is not present in the working
141       tree, then its absence is ignored. Git will avoid populating the
142       contents of those files, which makes a sparse checkout helpful when
143       working in a repository with many files, but only a few are important
144       to the current user.
145
146       The $GIT_DIR/info/sparse-checkout file is used to define the
147       skip-worktree reference bitmap. When Git updates the working directory,
148       it updates the skip-worktree bits in the index based on this file. The
149       files matching the patterns in the file will appear in the working
150       directory, and the rest will not.
151
152       To enable the sparse-checkout feature, run git sparse-checkout set to
153       set the patterns you want to use.
154
155       To repopulate the working directory with all files, use the git
156       sparse-checkout disable command.
157

FULL PATTERN SET

159       By default, the sparse-checkout file uses the same syntax as .gitignore
160       files.
161
162       While $GIT_DIR/info/sparse-checkout is usually used to specify what
163       files are included, you can also specify what files are not included,
164       using negative patterns. For example, to remove the file unwanted:
165
166           /*
167           !unwanted
168

CONE PATTERN SET

170       The full pattern set allows for arbitrary pattern matches and
171       complicated inclusion/exclusion rules. These can result in O(N*M)
172       pattern matches when updating the index, where N is the number of
173       patterns and M is the number of paths in the index. To combat this
174       performance issue, a more restricted pattern set is allowed when
175       core.sparseCheckoutCone is enabled.
176
177       The accepted patterns in the cone pattern set are:
178
179        1. Recursive: All paths inside a directory are included.
180
181        2. Parent: All files immediately inside a directory are included.
182
183       In addition to the above two patterns, we also expect that all files in
184       the root directory are included. If a recursive pattern is added, then
185       all leading directories are added as parent patterns.
186
187       By default, when running git sparse-checkout init, the root directory
188       is added as a parent pattern. At this point, the sparse-checkout file
189       contains the following patterns:
190
191           /*
192           !/*/
193
194       This says "include everything in root, but nothing two levels below
195       root."
196
197       When in cone mode, the git sparse-checkout set subcommand takes a list
198       of directories instead of a list of sparse-checkout patterns. In this
199       mode, the command git sparse-checkout set A/B/C sets the directory
200       A/B/C as a recursive pattern, the directories A and A/B are added as
201       parent patterns. The resulting sparse-checkout file is now
202
203           /*
204           !/*/
205           /A/
206           !/A/*/
207           /A/B/
208           !/A/B/*/
209           /A/B/C/
210
211       Here, order matters, so the negative patterns are overridden by the
212       positive patterns that appear lower in the file.
213
214       If core.sparseCheckoutCone=true, then Git will parse the
215       sparse-checkout file expecting patterns of these types. Git will warn
216       if the patterns do not match. If the patterns do match the expected
217       format, then Git will use faster hash- based algorithms to compute
218       inclusion in the sparse-checkout.
219
220       In the cone mode case, the git sparse-checkout list subcommand will
221       list the directories that define the recursive patterns. For the
222       example sparse-checkout file above, the output is as follows:
223
224           $ git sparse-checkout list
225           A/B/C
226
227       If core.ignoreCase=true, then the pattern-matching algorithm will use a
228       case-insensitive check. This corrects for case mismatched filenames in
229       the git sparse-checkout set command to reflect the expected cone in the
230       working directory.
231
232       When changing the sparse-checkout patterns in cone mode, Git will
233       inspect each tracked directory that is not within the sparse-checkout
234       cone to see if it contains any untracked files. If all of those files
235       are ignored due to the .gitignore patterns, then the directory will be
236       deleted. If any of the untracked files within that directory is not
237       ignored, then no deletions will occur within that directory and a
238       warning message will appear. If these files are important, then reset
239       your sparse-checkout definition so they are included, use git add and
240       git commit to store them, then remove any remaining files manually to
241       ensure Git can behave optimally.
242

SUBMODULES

244       If your repository contains one or more submodules, then submodules are
245       populated based on interactions with the git submodule command.
246       Specifically, git submodule init -- <path> will ensure the submodule at
247       <path> is present, while git submodule deinit [-f] -- <path> will
248       remove the files for the submodule at <path> (including any untracked
249       files, uncommitted changes, and unpushed history). Similar to how
250       sparse-checkout removes files from the working tree but still leaves
251       entries in the index, deinitialized submodules are removed from the
252       working directory but still have an entry in the index.
253
254       Since submodules may have unpushed changes or untracked files, removing
255       them could result in data loss. Thus, changing sparse
256       inclusion/exclusion rules will not cause an already checked out
257       submodule to be removed from the working copy. Said another way, just
258       as checkout will not cause submodules to be automatically removed or
259       initialized even when switching between branches that remove or add
260       submodules, using sparse-checkout to reduce or expand the scope of
261       "interesting" files will not cause submodules to be automatically
262       deinitialized or initialized either.
263
264       Further, the above facts mean that there are multiple reasons that
265       "tracked" files might not be present in the working copy: sparsity
266       pattern application from sparse-checkout, and submodule initialization
267       state. Thus, commands like git grep that work on tracked files in the
268       working copy may return results that are limited by either or both of
269       these restrictions.
270

SEE ALSO

272       git-read-tree(1) gitignore(5)
273

GIT

275       Part of the git(1) suite
276
277
278
279Git 2.36.1                        2022-05-05             GIT-SPARSE-CHECKOU(1)
Impressum