]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/git-sparse-checkout.txt
unpack-trees: failure to set SKIP_WORKTREE bits always just a warning
[thirdparty/git.git] / Documentation / git-sparse-checkout.txt
CommitLineData
94c0956b
DS
1git-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
757ff352 8given by a list of patterns.
94c0956b
DS
9
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'::
de11951b 31 Describe the patterns in the sparse-checkout file.
94c0956b 32
bab3c359
DS
33'init'::
34 Enable the `core.sparseCheckout` setting. If the
35 sparse-checkout file does not exist, then populate it with
36 patterns that match every file in the root directory and
37 no other directories, then will remove all directories tracked
38 by Git. Add patterns to the sparse-checkout file to
39 repopulate 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.
a402723e
MT
44+
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).
94c0956b 48
f6039a94
DS
49'set'::
50 Write a set of patterns to the sparse-checkout file, as given as
51 a list of arguments following the 'set' subcommand. Update the
52 working directory to match the new patterns. Enable the
53 core.sparseCheckout config setting if it is not already enabled.
7bffca95
DS
54+
55When the `--stdin` option is provided, the patterns are read from
56standard in as a newline-delimited list instead of from the arguments.
d2e65f4c
DS
57+
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.
f6039a94 65
2631dc87
DS
66'add'::
67 Update the sparse-checkout file to include additional patterns.
68 By default, these patterns are read from the command-line arguments,
69 but they can be read from stdin using the `--stdin` option. When
70 `core.sparseCheckoutCone` is enabled, the given patterns are interpreted
71 as directory names as in the 'set' subcommand.
72
72918c1a 73'disable'::
99dfa6f9
DS
74 Disable the `core.sparseCheckout` config setting, and restore the
75 working directory to include all files. Leaves the sparse-checkout
76 file intact so a later 'git sparse-checkout init' command may
77 return the working directory to the same state.
72918c1a 78
94c0956b
DS
79SPARSE CHECKOUT
80---------------
81
82"Sparse checkout" allows populating the working directory sparsely.
83It uses the skip-worktree bit (see linkgit:git-update-index[1]) to tell
84Git whether a file in the working directory is worth looking at. If
85the skip-worktree bit is set, then the file is ignored in the working
86directory. Git will not populate the contents of those files, which
87makes a sparse checkout helpful when working in a repository with many
88files, but only a few are important to the current user.
89
90The `$GIT_DIR/info/sparse-checkout` file is used to define the
91skip-worktree reference bitmap. When Git updates the working
92directory, it updates the skip-worktree bits in the index based
93on this file. The files matching the patterns in the file will
94appear in the working directory, and the rest will not.
95
72918c1a
DS
96To enable the sparse-checkout feature, run `git sparse-checkout init` to
97initialize a simple sparse-checkout file and enable the `core.sparseCheckout`
98config setting. Then, run `git sparse-checkout set` to modify the patterns in
99the sparse-checkout file.
100
101To repopulate the working directory with all files, use the
102`git sparse-checkout disable` command.
103
879321eb
DS
104
105FULL PATTERN SET
106----------------
94c0956b
DS
107
108By default, the sparse-checkout file uses the same syntax as `.gitignore`
109files.
110
111While `$GIT_DIR/info/sparse-checkout` is usually used to specify what
112files are included, you can also specify what files are _not_ included,
113using negative patterns. For example, to remove the file `unwanted`:
114
115----------------
116/*
117!unwanted
118----------------
119
94c0956b 120
879321eb
DS
121CONE PATTERN SET
122----------------
123
124The full pattern set allows for arbitrary pattern matches and complicated
125inclusion/exclusion rules. These can result in O(N*M) pattern matches when
126updating the index, where N is the number of patterns and M is the number
127of paths in the index. To combat this performance issue, a more restricted
7aa9ef2f 128pattern set is allowed when `core.sparseCheckoutCone` is enabled.
879321eb
DS
129
130The accepted patterns in the cone pattern set are:
131
1321. *Recursive:* All paths inside a directory are included.
133
1342. *Parent:* All files immediately inside a directory are included.
135
136In addition to the above two patterns, we also expect that all files in the
137root directory are included. If a recursive pattern is added, then all
138leading directories are added as parent patterns.
139
140By default, when running `git sparse-checkout init`, the root directory is
141added as a parent pattern. At this point, the sparse-checkout file contains
142the following patterns:
143
144----------------
145/*
146!/*/
147----------------
148
149This says "include everything in root, but nothing two levels below root."
d2e65f4c
DS
150
151When in cone mode, the `git sparse-checkout set` subcommand takes a list of
152directories instead of a list of sparse-checkout patterns. In this mode,
153the command `git sparse-checkout set A/B/C` sets the directory `A/B/C` as
154a recursive pattern, the directories `A` and `A/B` are added as parent
155patterns. The resulting sparse-checkout file is now
879321eb
DS
156
157----------------
158/*
159!/*/
160/A/
161!/A/*/
162/A/B/
163!/A/B/*/
164/A/B/C/
165----------------
166
167Here, order matters, so the negative patterns are overridden by the positive
168patterns that appear lower in the file.
169
170If `core.sparseCheckoutCone=true`, then Git will parse the sparse-checkout file
171expecting patterns of these types. Git will warn if the patterns do not match.
172If the patterns do match the expected format, then Git will use faster hash-
173based algorithms to compute inclusion in the sparse-checkout.
174
de11951b
DS
175In the cone mode case, the `git sparse-checkout list` subcommand will list the
176directories that define the recursive patterns. For the example sparse-checkout
177file above, the output is as follows:
178
179--------------------------
180$ git sparse-checkout list
181A/B/C
182--------------------------
183
190a65f9
DS
184If `core.ignoreCase=true`, then the pattern-matching algorithm will use a
185case-insensitive check. This corrects for case mismatched filenames in the
186'git sparse-checkout set' command to reflect the expected cone in the working
187directory.
188
4fd683b6
DS
189
190SUBMODULES
191----------
192
193If your repository contains one or more submodules, then those submodules will
194appear based on which you initialized with the `git submodule` command. If
195your sparse-checkout patterns exclude an initialized submodule, then that
196submodule will still appear in your working directory.
197
198
94c0956b
DS
199SEE ALSO
200--------
201
202linkgit:git-read-tree[1]
203linkgit:gitignore[5]
204
205GIT
206---
207Part of the linkgit:git[1] suite