blob: 1a3ace60820fac2fa71e3d555a4a17df8e4ec524 [file] [log] [blame]
Junio C Hamano2f5a9892019-12-25 21:12:551git-sparse-checkout(1)
2======================
3
4NAME
5----
6git-sparse-checkout - Initialize and modify the sparse-checkout
7configuration, which reduces the checkout to a set of paths
Junio C Hamano68793842020-01-06 23:07:098given by a list of patterns.
Junio C Hamano2f5a9892019-12-25 21:12:559
10
11SYNOPSIS
12--------
13[verse]
14'git sparse-checkout <subcommand> [options]'
15
16
17DESCRIPTION
18-----------
19
20Initialize and modify the sparse-checkout configuration, which reduces
21the checkout to a set of paths given by a list of patterns.
22
23THIS COMMAND IS EXPERIMENTAL. ITS BEHAVIOR, AND THE BEHAVIOR OF OTHER
24COMMANDS IN THE PRESENCE OF SPARSE-CHECKOUTS, WILL LIKELY CHANGE IN
25THE FUTURE.
26
27
28COMMANDS
29--------
30'list'::
Junio C Hamano68793842020-01-06 23:07:0931Describe the patterns in the sparse-checkout file.
Junio C Hamano2f5a9892019-12-25 21:12:5532
33'init'::
34Enable the `core.sparseCheckout` setting. If the
35sparse-checkout file does not exist, then populate it with
36patterns that match every file in the root directory and
37no other directories, then will remove all directories tracked
38by Git. Add patterns to the sparse-checkout file to
39repopulate the working directory.
40+
41To avoid interfering with other worktrees, it first enables the
42`extensions.worktreeConfig` setting and makes sure to set the
43`core.sparseCheckout` setting in the worktree-specific config file.
Junio C Hamanodac86772020-02-05 23:30:1344+
45When `--cone` is provided, the `core.sparseCheckoutCone` setting is
46also set, allowing for better performance with a limited set of
47patterns (see 'CONE PATTERN SET' below).
Junio C Hamano2f5a9892019-12-25 21:12:5548
49'set'::
50Write a set of patterns to the sparse-checkout file, as given as
51a list of arguments following the 'set' subcommand. Update the
52working directory to match the new patterns. Enable the
53core.sparseCheckout config setting if it is not already enabled.
54+
55When the `--stdin` option is provided, the patterns are read from
56standard in as a newline-delimited list instead of from the arguments.
Junio C Hamanofc6646b2020-02-14 23:35:1657+
58When `core.sparseCheckoutCone` is enabled, the input list is considered a
59list of directories instead of sparse-checkout patterns. The command writes
60patterns to the sparse-checkout file to include all files contained in those
61directories (recursively) as well as files that are siblings of ancestor
62directories. The input format matches the output of `git ls-tree --name-only`.
63This includes interpreting pathnames that begin with a double quote (") as
64C-style quoted strings.
Junio C Hamano2f5a9892019-12-25 21:12:5565
Junio C Hamanob082a532020-03-05 21:52:2566'add'::
67Update the sparse-checkout file to include additional patterns.
68By default, these patterns are read from the command-line arguments,
69but they can be read from stdin using the `--stdin` option. When
70`core.sparseCheckoutCone` is enabled, the given patterns are interpreted
71as directory names as in the 'set' subcommand.
72
Junio C Hamano67cc2b72020-04-30 00:03:2073'reapply::
74Reapply the sparsity pattern rules to paths in the working tree.
75Commands like merge or rebase can materialize paths to do their
76work (e.g. in order to show you a conflict), and other
77sparse-checkout commands might fail to sparsify an individual file
78(e.g. because it has unstaged changes or conflicts). In such
79cases, it can make sense to run `git sparse-checkout reapply` later
80after cleaning up affected paths (e.g. resolving conflicts, undoing
81or committing changes, etc.).
82
Junio C Hamano2f5a9892019-12-25 21:12:5583'disable'::
84Disable the `core.sparseCheckout` config setting, and restore the
85working directory to include all files. Leaves the sparse-checkout
86file intact so a later 'git sparse-checkout init' command may
87return the working directory to the same state.
88
89SPARSE CHECKOUT
90---------------
91
92"Sparse checkout" allows populating the working directory sparsely.
93It uses the skip-worktree bit (see linkgit:git-update-index[1]) to tell
94Git whether a file in the working directory is worth looking at. If
95the skip-worktree bit is set, then the file is ignored in the working
96directory. Git will not populate the contents of those files, which
97makes a sparse checkout helpful when working in a repository with many
98files, but only a few are important to the current user.
99
100The `$GIT_DIR/info/sparse-checkout` file is used to define the
101skip-worktree reference bitmap. When Git updates the working
102directory, it updates the skip-worktree bits in the index based
103on this file. The files matching the patterns in the file will
104appear in the working directory, and the rest will not.
105
106To enable the sparse-checkout feature, run `git sparse-checkout init` to
107initialize a simple sparse-checkout file and enable the `core.sparseCheckout`
108config setting. Then, run `git sparse-checkout set` to modify the patterns in
109the sparse-checkout file.
110
111To repopulate the working directory with all files, use the
112`git sparse-checkout disable` command.
113
114
115FULL PATTERN SET
116----------------
117
118By default, the sparse-checkout file uses the same syntax as `.gitignore`
119files.
120
121While `$GIT_DIR/info/sparse-checkout` is usually used to specify what
122files are included, you can also specify what files are _not_ included,
123using negative patterns. For example, to remove the file `unwanted`:
124
125----------------
126/*
127!unwanted
128----------------
129
130
131CONE PATTERN SET
132----------------
133
134The full pattern set allows for arbitrary pattern matches and complicated
135inclusion/exclusion rules. These can result in O(N*M) pattern matches when
136updating the index, where N is the number of patterns and M is the number
137of paths in the index. To combat this performance issue, a more restricted
Junio C Hamanofc6646b2020-02-14 23:35:16138pattern set is allowed when `core.sparseCheckoutCone` is enabled.
Junio C Hamano2f5a9892019-12-25 21:12:55139
140The accepted patterns in the cone pattern set are:
141
1421. *Recursive:* All paths inside a directory are included.
143
1442. *Parent:* All files immediately inside a directory are included.
145
146In addition to the above two patterns, we also expect that all files in the
147root directory are included. If a recursive pattern is added, then all
148leading directories are added as parent patterns.
149
150By default, when running `git sparse-checkout init`, the root directory is
151added as a parent pattern. At this point, the sparse-checkout file contains
152the following patterns:
153
154----------------
155/*
156!/*/
157----------------
158
159This says "include everything in root, but nothing two levels below root."
Junio C Hamanofc6646b2020-02-14 23:35:16160
161When in cone mode, the `git sparse-checkout set` subcommand takes a list of
162directories instead of a list of sparse-checkout patterns. In this mode,
163the command `git sparse-checkout set A/B/C` sets the directory `A/B/C` as
164a recursive pattern, the directories `A` and `A/B` are added as parent
165patterns. The resulting sparse-checkout file is now
Junio C Hamano2f5a9892019-12-25 21:12:55166
167----------------
168/*
169!/*/
170/A/
171!/A/*/
172/A/B/
173!/A/B/*/
174/A/B/C/
175----------------
176
177Here, order matters, so the negative patterns are overridden by the positive
178patterns that appear lower in the file.
179
180If `core.sparseCheckoutCone=true`, then Git will parse the sparse-checkout file
181expecting patterns of these types. Git will warn if the patterns do not match.
182If the patterns do match the expected format, then Git will use faster hash-
183based algorithms to compute inclusion in the sparse-checkout.
184
Junio C Hamano68793842020-01-06 23:07:09185In the cone mode case, the `git sparse-checkout list` subcommand will list the
186directories that define the recursive patterns. For the example sparse-checkout
187file above, the output is as follows:
188
189--------------------------
190$ git sparse-checkout list
191A/B/C
192--------------------------
193
Junio C Hamano2f5a9892019-12-25 21:12:55194If `core.ignoreCase=true`, then the pattern-matching algorithm will use a
195case-insensitive check. This corrects for case mismatched filenames in the
196'git sparse-checkout set' command to reflect the expected cone in the working
197directory.
198
Junio C Hamano68793842020-01-06 23:07:09199
200SUBMODULES
201----------
202
203If your repository contains one or more submodules, then those submodules will
204appear based on which you initialized with the `git submodule` command. If
205your sparse-checkout patterns exclude an initialized submodule, then that
206submodule will still appear in your working directory.
207
208
Junio C Hamano2f5a9892019-12-25 21:12:55209SEE ALSO
210--------
211
212linkgit:git-read-tree[1]
213linkgit:gitignore[5]
214
215GIT
216---
217Part of the linkgit:git[1] suite