1GIT-SPARSE-CHECKOU(1) Git Manual GIT-SPARSE-CHECKOU(1)
2
3
4
6 git-sparse-checkout - Initialize and modify the sparse-checkout
7 configuration, which reduces the checkout to a set of paths given by a
8 list of patterns.
9
11 git sparse-checkout <subcommand> [options]
12
14 Initialize and modify the sparse-checkout configuration, which reduces
15 the checkout to a set of paths given by a list of patterns.
16
17 THIS COMMAND IS EXPERIMENTAL. ITS BEHAVIOR, AND THE BEHAVIOR OF OTHER
18 COMMANDS IN THE PRESENCE OF SPARSE-CHECKOUTS, WILL LIKELY CHANGE IN THE
19 FUTURE.
20
22 list
23 Describe the patterns in the sparse-checkout file.
24
25 init
26 Enable the core.sparseCheckout setting. If the sparse-checkout file
27 does not exist, then populate it with patterns that match every
28 file in the root directory and no other directories, then will
29 remove all directories tracked by Git. Add patterns to the
30 sparse-checkout file to repopulate the working directory.
31
32 To avoid interfering with other worktrees, it first enables the
33 extensions.worktreeConfig setting and makes sure to set the
34 core.sparseCheckout setting in the worktree-specific config file.
35
36 When --cone is provided, the core.sparseCheckoutCone setting is
37 also set, allowing for better performance with a limited set of
38 patterns (see CONE PATTERN SET below).
39
40 set
41 Write a set of patterns to the sparse-checkout file, as given as a
42 list of arguments following the set subcommand. Update the working
43 directory to match the new patterns. Enable the core.sparseCheckout
44 config setting if it is not already enabled.
45
46 When the --stdin option is provided, the patterns are read from
47 standard in as a newline-delimited list instead of from the
48 arguments.
49
50 When core.sparseCheckoutCone is enabled, the input list is
51 considered a list of directories instead of sparse-checkout
52 patterns. The command writes patterns to the sparse-checkout file
53 to include all files contained in those directories (recursively)
54 as well as files that are siblings of ancestor directories. The
55 input format matches the output of git ls-tree --name-only. This
56 includes interpreting pathnames that begin with a double quote (")
57 as C-style quoted strings.
58
59 add
60 Update the sparse-checkout file to include additional patterns. By
61 default, these patterns are read from the command-line arguments,
62 but they can be read from stdin using the --stdin option. When
63 core.sparseCheckoutCone is enabled, the given patterns are
64 interpreted as directory names as in the set subcommand.
65
66 reapply
67 Reapply the sparsity pattern rules to paths in the working tree.
68 Commands like merge or rebase can materialize paths to do their
69 work (e.g. in order to show you a conflict), and other
70 sparse-checkout commands might fail to sparsify an individual file
71 (e.g. because it has unstaged changes or conflicts). In such cases,
72 it can make sense to run git sparse-checkout reapply later after
73 cleaning up affected paths (e.g. resolving conflicts, undoing or
74 committing changes, etc.).
75
76 disable
77 Disable the core.sparseCheckout config setting, and restore the
78 working directory to include all files. Leaves the sparse-checkout
79 file intact so a later git sparse-checkout init command may return
80 the working directory to the same state.
81
83 "Sparse checkout" allows populating the working directory sparsely. It
84 uses the skip-worktree bit (see git-update-index(1)) to tell Git
85 whether a file in the working directory is worth looking at. If the
86 skip-worktree bit is set, then the file is ignored in the working
87 directory. Git will not populate the contents of those files, which
88 makes a sparse checkout helpful when working in a repository with many
89 files, but only a few are important to the current user.
90
91 The $GIT_DIR/info/sparse-checkout file is used to define the
92 skip-worktree reference bitmap. When Git updates the working directory,
93 it updates the skip-worktree bits in the index based on this file. The
94 files matching the patterns in the file will appear in the working
95 directory, and the rest will not.
96
97 To enable the sparse-checkout feature, run git sparse-checkout init to
98 initialize a simple sparse-checkout file and enable the
99 core.sparseCheckout config setting. Then, run git sparse-checkout set
100 to modify the patterns in the sparse-checkout file.
101
102 To repopulate the working directory with all files, use the git
103 sparse-checkout disable command.
104
106 By default, the sparse-checkout file uses the same syntax as .gitignore
107 files.
108
109 While $GIT_DIR/info/sparse-checkout is usually used to specify what
110 files are included, you can also specify what files are not included,
111 using negative patterns. For example, to remove the file unwanted:
112
113 /*
114 !unwanted
115
117 The full pattern set allows for arbitrary pattern matches and
118 complicated inclusion/exclusion rules. These can result in O(N*M)
119 pattern matches when updating the index, where N is the number of
120 patterns and M is the number of paths in the index. To combat this
121 performance issue, a more restricted pattern set is allowed when
122 core.sparseCheckoutCone is enabled.
123
124 The accepted patterns in the cone pattern set are:
125
126 1. Recursive: All paths inside a directory are included.
127
128 2. Parent: All files immediately inside a directory are included.
129
130 In addition to the above two patterns, we also expect that all files in
131 the root directory are included. If a recursive pattern is added, then
132 all leading directories are added as parent patterns.
133
134 By default, when running git sparse-checkout init, the root directory
135 is added as a parent pattern. At this point, the sparse-checkout file
136 contains the following patterns:
137
138 /*
139 !/*/
140
141 This says "include everything in root, but nothing two levels below
142 root."
143
144 When in cone mode, the git sparse-checkout set subcommand takes a list
145 of directories instead of a list of sparse-checkout patterns. In this
146 mode, the command git sparse-checkout set A/B/C sets the directory
147 A/B/C as a recursive pattern, the directories A and A/B are added as
148 parent patterns. The resulting sparse-checkout file is now
149
150 /*
151 !/*/
152 /A/
153 !/A/*/
154 /A/B/
155 !/A/B/*/
156 /A/B/C/
157
158 Here, order matters, so the negative patterns are overridden by the
159 positive patterns that appear lower in the file.
160
161 If core.sparseCheckoutCone=true, then Git will parse the
162 sparse-checkout file expecting patterns of these types. Git will warn
163 if the patterns do not match. If the patterns do match the expected
164 format, then Git will use faster hash- based algorithms to compute
165 inclusion in the sparse-checkout.
166
167 In the cone mode case, the git sparse-checkout list subcommand will
168 list the directories that define the recursive patterns. For the
169 example sparse-checkout file above, the output is as follows:
170
171 $ git sparse-checkout list
172 A/B/C
173
174 If core.ignoreCase=true, then the pattern-matching algorithm will use a
175 case-insensitive check. This corrects for case mismatched filenames in
176 the git sparse-checkout set command to reflect the expected cone in the
177 working directory.
178
180 If your repository contains one or more submodules, then submodules are
181 populated based on interactions with the git submodule command.
182 Specifically, git submodule init -- <path> will ensure the submodule at
183 <path> is present, while git submodule deinit [-f] -- <path> will
184 remove the files for the submodule at <path> (including any untracked
185 files, uncommitted changes, and unpushed history). Similar to how
186 sparse-checkout removes files from the working tree but still leaves
187 entries in the index, deinitialized submodules are removed from the
188 working directory but still have an entry in the index.
189
190 Since submodules may have unpushed changes or untracked files, removing
191 them could result in data loss. Thus, changing sparse
192 inclusion/exclusion rules will not cause an already checked out
193 submodule to be removed from the working copy. Said another way, just
194 as checkout will not cause submodules to be automatically removed or
195 initialized even when switching between branches that remove or add
196 submodules, using sparse-checkout to reduce or expand the scope of
197 "interesting" files will not cause submodules to be automatically
198 deinitialized or initialized either.
199
200 Further, the above facts mean that there are multiple reasons that
201 "tracked" files might not be present in the working copy: sparsity
202 pattern application from sparse-checkout, and submodule initialization
203 state. Thus, commands like git grep that work on tracked files in the
204 working copy may return results that are limited by either or both of
205 these restrictions.
206
208 git-read-tree(1) gitignore(5)
209
211 Part of the git(1) suite
212
213
214
215Git 2.30.2 2021-03-08 GIT-SPARSE-CHECKOU(1)