Merge branch 'jt/connectivity-check-optim-in-partial-clone'
[git] / Documentation / git-sparse-checkout.txt
1 git-sparse-checkout(1)
2 ======================
3
4 NAME
5 ----
6 git-sparse-checkout - Initialize and modify the sparse-checkout
7 configuration, which reduces the checkout to a set of paths
8 given by a list of patterns.
9
10
11 SYNOPSIS
12 --------
13 [verse]
14 'git sparse-checkout <subcommand> [options]'
15
16
17 DESCRIPTION
18 -----------
19
20 Initialize and modify the sparse-checkout configuration, which reduces
21 the checkout to a set of paths given by a list of patterns.
22
23 THIS COMMAND IS EXPERIMENTAL. ITS BEHAVIOR, AND THE BEHAVIOR OF OTHER
24 COMMANDS IN THE PRESENCE OF SPARSE-CHECKOUTS, WILL LIKELY CHANGE IN
25 THE FUTURE.
26
27
28 COMMANDS
29 --------
30 'list'::
31         Describe the patterns in the sparse-checkout file.
32
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 +
41 To 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.
44 +
45 When `--cone` is provided, the `core.sparseCheckoutCone` setting is
46 also set, allowing for better performance with a limited set of
47 patterns (see 'CONE PATTERN SET' below).
48
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.
54 +
55 When the `--stdin` option is provided, the patterns are read from
56 standard in as a newline-delimited list instead of from the arguments.
57
58 'disable'::
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.
63
64 SPARSE CHECKOUT
65 ---------------
66
67 "Sparse checkout" allows populating the working directory sparsely.
68 It uses the skip-worktree bit (see linkgit:git-update-index[1]) to tell
69 Git whether a file in the working directory is worth looking at. If
70 the skip-worktree bit is set, then the file is ignored in the working
71 directory. Git will not populate the contents of those files, which
72 makes a sparse checkout helpful when working in a repository with many
73 files, but only a few are important to the current user.
74
75 The `$GIT_DIR/info/sparse-checkout` file is used to define the
76 skip-worktree reference bitmap. When Git updates the working
77 directory, it updates the skip-worktree bits in the index based
78 on this file. The files matching the patterns in the file will
79 appear in the working directory, and the rest will not.
80
81 To enable the sparse-checkout feature, run `git sparse-checkout init` to
82 initialize a simple sparse-checkout file and enable the `core.sparseCheckout`
83 config setting. Then, run `git sparse-checkout set` to modify the patterns in
84 the sparse-checkout file.
85
86 To repopulate the working directory with all files, use the
87 `git sparse-checkout disable` command.
88
89
90 FULL PATTERN SET
91 ----------------
92
93 By default, the sparse-checkout file uses the same syntax as `.gitignore`
94 files.
95
96 While `$GIT_DIR/info/sparse-checkout` is usually used to specify what
97 files are included, you can also specify what files are _not_ included,
98 using negative patterns. For example, to remove the file `unwanted`:
99
100 ----------------
101 /*
102 !unwanted
103 ----------------
104
105
106 CONE PATTERN SET
107 ----------------
108
109 The full pattern set allows for arbitrary pattern matches and complicated
110 inclusion/exclusion rules. These can result in O(N*M) pattern matches when
111 updating the index, where N is the number of patterns and M is the number
112 of paths in the index. To combat this performance issue, a more restricted
113 pattern set is allowed when `core.spareCheckoutCone` is enabled.
114
115 The accepted patterns in the cone pattern set are:
116
117 1. *Recursive:* All paths inside a directory are included.
118
119 2. *Parent:* All files immediately inside a directory are included.
120
121 In addition to the above two patterns, we also expect that all files in the
122 root directory are included. If a recursive pattern is added, then all
123 leading directories are added as parent patterns.
124
125 By default, when running `git sparse-checkout init`, the root directory is
126 added as a parent pattern. At this point, the sparse-checkout file contains
127 the following patterns:
128
129 ----------------
130 /*
131 !/*/
132 ----------------
133
134 This says "include everything in root, but nothing two levels below root."
135 If 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
137 now
138
139 ----------------
140 /*
141 !/*/
142 /A/
143 !/A/*/
144 /A/B/
145 !/A/B/*/
146 /A/B/C/
147 ----------------
148
149 Here, order matters, so the negative patterns are overridden by the positive
150 patterns that appear lower in the file.
151
152 If `core.sparseCheckoutCone=true`, then Git will parse the sparse-checkout file
153 expecting patterns of these types. Git will warn if the patterns do not match.
154 If the patterns do match the expected format, then Git will use faster hash-
155 based algorithms to compute inclusion in the sparse-checkout.
156
157 In the cone mode case, the `git sparse-checkout list` subcommand will list the
158 directories that define the recursive patterns. For the example sparse-checkout
159 file above, the output is as follows:
160
161 --------------------------
162 $ git sparse-checkout list
163 A/B/C
164 --------------------------
165
166 If `core.ignoreCase=true`, then the pattern-matching algorithm will use a
167 case-insensitive check. This corrects for case mismatched filenames in the
168 'git sparse-checkout set' command to reflect the expected cone in the working
169 directory.
170
171
172 SUBMODULES
173 ----------
174
175 If your repository contains one or more submodules, then those submodules will
176 appear based on which you initialized with the `git submodule` command. If
177 your sparse-checkout patterns exclude an initialized submodule, then that
178 submodule will still appear in your working directory.
179
180
181 SEE ALSO
182 --------
183
184 linkgit:git-read-tree[1]
185 linkgit:gitignore[5]
186
187 GIT
188 ---
189 Part of the linkgit:git[1] suite