sparse-checkout: document interactions with submodules
[git.git] / Documentation / git-sparse-checkout.txt
blob3b341cf0fce3c173d9b953e82dd5f3b0453f5603
1 git-sparse-checkout(1)
2 ======================
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 atterns.
11 SYNOPSIS
12 --------
13 [verse]
14 'git sparse-checkout <subcommand> [options]'
17 DESCRIPTION
18 -----------
20 Initialize and modify the sparse-checkout configuration, which reduces
21 the checkout to a set of paths given by a list of patterns.
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.
28 COMMANDS
29 --------
30 'list'::
31         Describe the patterns in the sparse-checkout file.
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.
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.
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.
51 When the `--stdin` option is provided, the patterns are read from
52 standard in as a newline-delimited list instead of from the arguments.
54 'disable'::
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.
60 SPARSE CHECKOUT
61 ---------------
63 "Sparse checkout" allows populating the working directory sparsely.
64 It uses the skip-worktree bit (see linkgit:git-update-index[1]) to tell
65 Git whether a file in the working directory is worth looking at. If
66 the skip-worktree bit is set, then the file is ignored in the working
67 directory. Git will not populate the contents of those files, which
68 makes a sparse checkout helpful when working in a repository with many
69 files, but only a few are important to the current user.
71 The `$GIT_DIR/info/sparse-checkout` file is used to define the
72 skip-worktree reference bitmap. When Git updates the working
73 directory, it updates the skip-worktree bits in the index based
74 on this file. The files matching the patterns in the file will
75 appear in the working directory, and the rest will not.
77 To enable the sparse-checkout feature, run `git sparse-checkout init` to
78 initialize a simple sparse-checkout file and enable the `core.sparseCheckout`
79 config setting. Then, run `git sparse-checkout set` to modify the patterns in
80 the sparse-checkout file.
82 To repopulate the working directory with all files, use the
83 `git sparse-checkout disable` command.
86 FULL PATTERN SET
87 ----------------
89 By default, the sparse-checkout file uses the same syntax as `.gitignore`
90 files.
92 While `$GIT_DIR/info/sparse-checkout` is usually used to specify what
93 files are included, you can also specify what files are _not_ included,
94 using negative patterns. For example, to remove the file `unwanted`:
96 ----------------
98 !unwanted
99 ----------------
102 CONE PATTERN SET
103 ----------------
105 The full pattern set allows for arbitrary pattern matches and complicated
106 inclusion/exclusion rules. These can result in O(N*M) pattern matches when
107 updating the index, where N is the number of patterns and M is the number
108 of paths in the index. To combat this performance issue, a more restricted
109 pattern set is allowed when `core.spareCheckoutCone` is enabled.
111 The accepted patterns in the cone pattern set are:
113 1. *Recursive:* All paths inside a directory are included.
115 2. *Parent:* All files immediately inside a directory are included.
117 In addition to the above two patterns, we also expect that all files in the
118 root directory are included. If a recursive pattern is added, then all
119 leading directories are added as parent patterns.
121 By default, when running `git sparse-checkout init`, the root directory is
122 added as a parent pattern. At this point, the sparse-checkout file contains
123 the following patterns:
125 ----------------
127 !/*/
128 ----------------
130 This says "include everything in root, but nothing two levels below root."
131 If 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
135 ----------------
137 !/*/
139 !/A/*/
140 /A/B/
141 !/A/B/*/
142 /A/B/C/
143 ----------------
145 Here, order matters, so the negative patterns are overridden by the positive
146 patterns that appear lower in the file.
148 If `core.sparseCheckoutCone=true`, then Git will parse the sparse-checkout file
149 expecting patterns of these types. Git will warn if the patterns do not match.
150 If the patterns do match the expected format, then Git will use faster hash-
151 based algorithms to compute inclusion in the sparse-checkout.
153 In the cone mode case, the `git sparse-checkout list` subcommand will list the
154 directories that define the recursive patterns. For the example sparse-checkout
155 file above, the output is as follows:
157 --------------------------
158 $ git sparse-checkout list
159 A/B/C
160 --------------------------
162 If `core.ignoreCase=true`, then the pattern-matching algorithm will use a
163 case-insensitive check. This corrects for case mismatched filenames in the
164 'git sparse-checkout set' command to reflect the expected cone in the working
165 directory.
168 SUBMODULES
169 ----------
171 If your repository contains one or more submodules, then those submodules will
172 appear based on which you initialized with the `git submodule` command. If
173 your sparse-checkout patterns exclude an initialized submodule, then that
174 submodule will still appear in your working directory.
177 SEE ALSO
178 --------
180 linkgit:git-read-tree[1]
181 linkgit:gitignore[5]
185 Part of the linkgit:git[1] suite