]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/git-sparse-checkout.txt
sparse-checkout: update working directory in-process
[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
8given by a list of atterns.
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'::
31 Provide a list of the contents in the sparse-checkout file.
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
DS
54'disable'::
55 Remove the sparse-checkout file, set `core.sparseCheckout` to
56 `false`, and restore the working directory to include all files.
57
94c0956b
DS
58SPARSE CHECKOUT
59---------------
60
61"Sparse checkout" allows populating the working directory sparsely.
62It uses the skip-worktree bit (see linkgit:git-update-index[1]) to tell
63Git whether a file in the working directory is worth looking at. If
64the skip-worktree bit is set, then the file is ignored in the working
65directory. Git will not populate the contents of those files, which
66makes a sparse checkout helpful when working in a repository with many
67files, but only a few are important to the current user.
68
69The `$GIT_DIR/info/sparse-checkout` file is used to define the
70skip-worktree reference bitmap. When Git updates the working
71directory, it updates the skip-worktree bits in the index based
72on this file. The files matching the patterns in the file will
73appear in the working directory, and the rest will not.
74
72918c1a
DS
75To enable the sparse-checkout feature, run `git sparse-checkout init` to
76initialize a simple sparse-checkout file and enable the `core.sparseCheckout`
77config setting. Then, run `git sparse-checkout set` to modify the patterns in
78the sparse-checkout file.
79
80To repopulate the working directory with all files, use the
81`git sparse-checkout disable` command.
82
879321eb
DS
83
84FULL PATTERN SET
85----------------
94c0956b
DS
86
87By default, the sparse-checkout file uses the same syntax as `.gitignore`
88files.
89
90While `$GIT_DIR/info/sparse-checkout` is usually used to specify what
91files are included, you can also specify what files are _not_ included,
92using negative patterns. For example, to remove the file `unwanted`:
93
94----------------
95/*
96!unwanted
97----------------
98
94c0956b 99
879321eb
DS
100CONE PATTERN SET
101----------------
102
103The full pattern set allows for arbitrary pattern matches and complicated
104inclusion/exclusion rules. These can result in O(N*M) pattern matches when
105updating the index, where N is the number of patterns and M is the number
106of paths in the index. To combat this performance issue, a more restricted
107pattern set is allowed when `core.spareCheckoutCone` is enabled.
108
109The accepted patterns in the cone pattern set are:
110
1111. *Recursive:* All paths inside a directory are included.
112
1132. *Parent:* All files immediately inside a directory are included.
114
115In addition to the above two patterns, we also expect that all files in the
116root directory are included. If a recursive pattern is added, then all
117leading directories are added as parent patterns.
118
119By default, when running `git sparse-checkout init`, the root directory is
120added as a parent pattern. At this point, the sparse-checkout file contains
121the following patterns:
122
123----------------
124/*
125!/*/
126----------------
127
128This says "include everything in root, but nothing two levels below root."
129If we then add the folder `A/B/C` as a recursive pattern, the folders `A` and
130`A/B` are added as parent patterns. The resulting sparse-checkout file is
131now
132
133----------------
134/*
135!/*/
136/A/
137!/A/*/
138/A/B/
139!/A/B/*/
140/A/B/C/
141----------------
142
143Here, order matters, so the negative patterns are overridden by the positive
144patterns that appear lower in the file.
145
146If `core.sparseCheckoutCone=true`, then Git will parse the sparse-checkout file
147expecting patterns of these types. Git will warn if the patterns do not match.
148If the patterns do match the expected format, then Git will use faster hash-
149based algorithms to compute inclusion in the sparse-checkout.
150
94c0956b
DS
151SEE ALSO
152--------
153
154linkgit:git-read-tree[1]
155linkgit:gitignore[5]
156
157GIT
158---
159Part of the linkgit:git[1] suite