]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/git-sparse-checkout.txt
Merge branch 'hw/doc-git-dir'
[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.
f6039a94 57
72918c1a 58'disable'::
99dfa6f9
DS
59 Disable the `core.sparseCheckout` config setting, and restore the
60 working directory to include all files. Leaves the sparse-checkout
61 file intact so a later 'git sparse-checkout init' command may
62 return the working directory to the same state.
72918c1a 63
94c0956b
DS
64SPARSE CHECKOUT
65---------------
66
67"Sparse checkout" allows populating the working directory sparsely.
68It uses the skip-worktree bit (see linkgit:git-update-index[1]) to tell
69Git whether a file in the working directory is worth looking at. If
70the skip-worktree bit is set, then the file is ignored in the working
71directory. Git will not populate the contents of those files, which
72makes a sparse checkout helpful when working in a repository with many
73files, but only a few are important to the current user.
74
75The `$GIT_DIR/info/sparse-checkout` file is used to define the
76skip-worktree reference bitmap. When Git updates the working
77directory, it updates the skip-worktree bits in the index based
78on this file. The files matching the patterns in the file will
79appear in the working directory, and the rest will not.
80
72918c1a
DS
81To enable the sparse-checkout feature, run `git sparse-checkout init` to
82initialize a simple sparse-checkout file and enable the `core.sparseCheckout`
83config setting. Then, run `git sparse-checkout set` to modify the patterns in
84the sparse-checkout file.
85
86To repopulate the working directory with all files, use the
87`git sparse-checkout disable` command.
88
879321eb
DS
89
90FULL PATTERN SET
91----------------
94c0956b
DS
92
93By default, the sparse-checkout file uses the same syntax as `.gitignore`
94files.
95
96While `$GIT_DIR/info/sparse-checkout` is usually used to specify what
97files are included, you can also specify what files are _not_ included,
98using negative patterns. For example, to remove the file `unwanted`:
99
100----------------
101/*
102!unwanted
103----------------
104
94c0956b 105
879321eb
DS
106CONE PATTERN SET
107----------------
108
109The full pattern set allows for arbitrary pattern matches and complicated
110inclusion/exclusion rules. These can result in O(N*M) pattern matches when
111updating the index, where N is the number of patterns and M is the number
112of paths in the index. To combat this performance issue, a more restricted
113pattern set is allowed when `core.spareCheckoutCone` is enabled.
114
115The accepted patterns in the cone pattern set are:
116
1171. *Recursive:* All paths inside a directory are included.
118
1192. *Parent:* All files immediately inside a directory are included.
120
121In addition to the above two patterns, we also expect that all files in the
122root directory are included. If a recursive pattern is added, then all
123leading directories are added as parent patterns.
124
125By default, when running `git sparse-checkout init`, the root directory is
126added as a parent pattern. At this point, the sparse-checkout file contains
127the following patterns:
128
129----------------
130/*
131!/*/
132----------------
133
134This says "include everything in root, but nothing two levels below root."
135If we then add the folder `A/B/C` as a recursive pattern, the folders `A` and
136`A/B` are added as parent patterns. The resulting sparse-checkout file is
137now
138
139----------------
140/*
141!/*/
142/A/
143!/A/*/
144/A/B/
145!/A/B/*/
146/A/B/C/
147----------------
148
149Here, order matters, so the negative patterns are overridden by the positive
150patterns that appear lower in the file.
151
152If `core.sparseCheckoutCone=true`, then Git will parse the sparse-checkout file
153expecting patterns of these types. Git will warn if the patterns do not match.
154If the patterns do match the expected format, then Git will use faster hash-
155based algorithms to compute inclusion in the sparse-checkout.
156
de11951b
DS
157In the cone mode case, the `git sparse-checkout list` subcommand will list the
158directories that define the recursive patterns. For the example sparse-checkout
159file above, the output is as follows:
160
161--------------------------
162$ git sparse-checkout list
163A/B/C
164--------------------------
165
190a65f9
DS
166If `core.ignoreCase=true`, then the pattern-matching algorithm will use a
167case-insensitive check. This corrects for case mismatched filenames in the
168'git sparse-checkout set' command to reflect the expected cone in the working
169directory.
170
4fd683b6
DS
171
172SUBMODULES
173----------
174
175If your repository contains one or more submodules, then those submodules will
176appear based on which you initialized with the `git submodule` command. If
177your sparse-checkout patterns exclude an initialized submodule, then that
178submodule will still appear in your working directory.
179
180
94c0956b
DS
181SEE ALSO
182--------
183
184linkgit:git-read-tree[1]
185linkgit:gitignore[5]
186
187GIT
188---
189Part of the linkgit:git[1] suite