1GIT-SUBMODULE(1) Git Manual GIT-SUBMODULE(1)
2
3
4
6 git-submodule - Initialize, update or inspect submodules
7
9 git submodule [--quiet] add [-b branch] [-f|--force]
10 [--reference <repository>] [--] <repository> [<path>]
11 git submodule [--quiet] status [--cached] [--recursive] [--] [<path>...]
12 git submodule [--quiet] init [--] [<path>...]
13 git submodule [--quiet] update [--init] [-N|--no-fetch] [--rebase]
14 [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
15 git submodule [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
16 git submodule [--quiet] foreach [--recursive] <command>
17 git submodule [--quiet] sync [--] [<path>...]
18
19
21 Submodules allow foreign repositories to be embedded within a dedicated
22 subdirectory of the source tree, always pointed at a particular commit.
23
24 They are not to be confused with remotes, which are meant mainly for
25 branches of the same project; submodules are meant for different
26 projects you would like to make part of your source tree, while the
27 history of the two projects still stays completely independent and you
28 cannot modify the contents of the submodule from within the main
29 project. If you want to merge the project histories and want to treat
30 the aggregated whole as a single project from then on, you may want to
31 add a remote for the other project and use the subtree merge strategy,
32 instead of treating the other project as a submodule. Directories that
33 come from both projects can be cloned and checked out as a whole if you
34 choose to go that route.
35
36 Submodules are composed from a so-called gitlink tree entry in the main
37 repository that refers to a particular commit object within the inner
38 repository that is completely separate. A record in the .gitmodules
39 file at the root of the source tree assigns a logical name to the
40 submodule and describes the default URL the submodule shall be cloned
41 from. The logical name can be used for overriding this URL within your
42 local repository configuration (see submodule init).
43
44 This command will manage the tree entries and contents of the
45 gitmodules file for you, as well as inspect the status of your
46 submodules and update them. When adding a new submodule to the tree,
47 the add subcommand is to be used. However, when pulling a tree
48 containing submodules, these will not be checked out by default; the
49 init and update subcommands will maintain submodules checked out and at
50 appropriate revision in your working tree. You can briefly inspect the
51 up-to-date status of your submodules using the status subcommand and
52 get a detailed overview of the difference between the index and
53 checkouts using the summary subcommand.
54
56 add
57 Add the given repository as a submodule at the given path to the
58 changeset to be committed next to the current project: the current
59 project is termed the "superproject".
60
61 This requires at least one argument: <repository>. The optional
62 argument <path> is the relative location for the cloned submodule
63 to exist in the superproject. If <path> is not given, the
64 "humanish" part of the source repository is used ("repo" for
65 "/path/to/repo.git" and "foo" for "host.xz:foo/.git").
66
67 <repository> is the URL of the new submodule’s origin repository.
68 This may be either an absolute URL, or (if it begins with ./ or
69 ../), the location relative to the superproject’s origin
70 repository.
71
72 <path> is the relative location for the cloned submodule to exist
73 in the superproject. If <path> does not exist, then the submodule
74 is created by cloning from the named URL. If <path> does exist and
75 is already a valid git repository, then this is added to the
76 changeset without cloning. This second form is provided to ease
77 creating a new submodule from scratch, and presumes the user will
78 later push the submodule to the given URL.
79
80 In either case, the given URL is recorded into .gitmodules for use
81 by subsequent users cloning the superproject. If the URL is given
82 relative to the superproject’s repository, the presumption is the
83 superproject and submodule repositories will be kept together in
84 the same relative location, and only the superproject’s URL needs
85 to be provided: git-submodule will correctly locate the submodule
86 using the relative URL in .gitmodules.
87
88 status
89 Show the status of the submodules. This will print the SHA-1 of the
90 currently checked out commit for each submodule, along with the
91 submodule path and the output of git describe for the SHA-1. Each
92 SHA-1 will be prefixed with - if the submodule is not initialized,
93 + if the currently checked out submodule commit does not match the
94 SHA-1 found in the index of the containing repository and U if the
95 submodule has merge conflicts. This command is the default command
96 for git submodule.
97
98 If --recursive is specified, this command will recurse into nested
99 submodules, and show their status as well.
100
101 init
102 Initialize the submodules, i.e. register each submodule name and
103 url found in .gitmodules into .git/config. The key used in
104 .git/config is submodule.$name.url. This command does not alter
105 existing information in .git/config. You can then customize the
106 submodule clone URLs in .git/config for your local setup and
107 proceed to git submodule update; you can also just use git
108 submodule update --init without the explicit init step if you do
109 not intend to customize any submodule locations.
110
111 update
112 Update the registered submodules, i.e. clone missing submodules and
113 checkout the commit specified in the index of the containing
114 repository. This will make the submodules HEAD be detached unless
115 --rebase or --merge is specified or the key submodule.$name.update
116 is set to rebase or merge.
117
118 If the submodule is not yet initialized, and you just want to use
119 the setting as stored in .gitmodules, you can automatically
120 initialize the submodule with the --init option.
121
122 If --recursive is specified, this command will recurse into the
123 registered submodules, and update any nested submodules within.
124
125 summary
126 Show commit summary between the given commit (defaults to HEAD) and
127 working tree/index. For a submodule in question, a series of
128 commits in the submodule between the given super project commit and
129 the index or working tree (switched by --cached) are shown. If the
130 option --files is given, show the series of commits in the
131 submodule between the index of the super project and the working
132 tree of the submodule (this option doesn’t allow to use the
133 --cached option or to provide an explicit commit).
134
135 foreach
136 Evaluates an arbitrary shell command in each checked out submodule.
137 The command has access to the variables $name, $path, $sha1 and
138 $toplevel: $name is the name of the relevant submodule section in
139 .gitmodules, $path is the name of the submodule directory relative
140 to the superproject, $sha1 is the commit as recorded in the
141 superproject, and $toplevel is the absolute path to the top-level
142 of the superproject. Any submodules defined in the superproject but
143 not checked out are ignored by this command. Unless given --quiet,
144 foreach prints the name of each submodule before evaluating the
145 command. If --recursive is given, submodules are traversed
146 recursively (i.e. the given shell command is evaluated in nested
147 submodules as well). A non-zero return from the command in any
148 submodule causes the processing to terminate. This can be
149 overridden by adding || : to the end of the command.
150
151 As an example, git submodule foreach 'echo $path `git rev-parse
152 HEAD`' will show the path and currently checked out commit for each
153 submodule.
154
155 sync
156 Synchronizes submodules' remote URL configuration setting to the
157 value specified in .gitmodules. This is useful when submodule URLs
158 change upstream and you need to update your local repositories
159 accordingly.
160
161 "git submodule sync" synchronizes all submodules while "git
162 submodule sync — A" synchronizes submodule "A" only.
163
165 -q, --quiet
166 Only print error messages.
167
168 -b, --branch
169 Branch of repository to add as submodule.
170
171 -f, --force
172 This option is only valid for the add command. Allow adding an
173 otherwise ignored submodule path.
174
175 --cached
176 This option is only valid for status and summary commands. These
177 commands typically use the commit found in the submodule HEAD, but
178 with this option, the commit stored in the index is used instead.
179
180 --files
181 This option is only valid for the summary command. This command
182 compares the commit in the index with that in the submodule HEAD
183 when this option is used.
184
185 -n, --summary-limit
186 This option is only valid for the summary command. Limit the
187 summary size (number of commits shown in total). Giving 0 will
188 disable the summary; a negative number means unlimited (the
189 default). This limit only applies to modified submodules. The size
190 is always limited to 1 for added/deleted/typechanged submodules.
191
192 -N, --no-fetch
193 This option is only valid for the update command. Don’t fetch new
194 objects from the remote site.
195
196 --merge
197 This option is only valid for the update command. Merge the commit
198 recorded in the superproject into the current branch of the
199 submodule. If this option is given, the submodule’s HEAD will not
200 be detached. If a merge failure prevents this process, you will
201 have to resolve the resulting conflicts within the submodule with
202 the usual conflict resolution tools. If the key
203 submodule.$name.update is set to merge, this option is implicit.
204
205 --rebase
206 This option is only valid for the update command. Rebase the
207 current branch onto the commit recorded in the superproject. If
208 this option is given, the submodule’s HEAD will not be detached. If
209 a merge failure prevents this process, you will have to resolve
210 these failures with git-rebase(1). If the key
211 submodule.$name.update is set to rebase, this option is implicit.
212
213 --reference <repository>
214 This option is only valid for add and update commands. These
215 commands sometimes need to clone a remote repository. In this case,
216 this option will be passed to the git-clone(1) command.
217
218 NOTE: Do not use this option unless you have read the note for git-
219 clone(1)'s --reference and --shared options carefully.
220
221 --recursive
222 This option is only valid for foreach, update and status commands.
223 Traverse submodules recursively. The operation is performed not
224 only in the submodules of the current repo, but also in any nested
225 submodules inside those submodules (and so on).
226
227 <path>...
228 Paths to submodule(s). When specified this will restrict the
229 command to only operate on the submodules found at the specified
230 paths. (This argument is required with add).
231
233 When initializing submodules, a .gitmodules file in the top-level
234 directory of the containing repository is used to find the url of each
235 submodule. This file should be formatted in the same way as
236 $GIT_DIR/config. The key to each submodule url is
237 "submodule.$name.url". See gitmodules(5) for details.
238
240 Written by Lars Hjemli <hjemli@gmail.com[1]>
241
243 Part of the git(1) suite
244
246 1. hjemli@gmail.com
247 mailto:hjemli@gmail.com
248
249
250
251Git 1.7.4.4 04/11/2011 GIT-SUBMODULE(1)