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