blob: 5e7a4130eeec48c27abf92b37834613692446723 [file] [log] [blame]
Lars Hjemli70c7ac22007-05-26 15:56:40 +02001git-submodule(1)
2================
3
4NAME
5----
6git-submodule - Initialize, update or inspect submodules
7
8
9SYNOPSIS
10--------
Matt Kraaib2493642007-07-06 17:56:31 -070011[verse]
Jens Lehmannd27b8762010-07-17 17:11:43 +020012'git submodule' [--quiet] add [-b branch] [-f|--force]
Jens Lehmann1414e572009-09-22 17:10:12 +020013 [--reference <repository>] [--] <repository> [<path>]
Johan Herland64b19ff2009-08-19 03:45:24 +020014'git submodule' [--quiet] status [--cached] [--recursive] [--] [<path>...]
Jonathan Niederb1889c32008-06-30 01:09:04 -050015'git submodule' [--quiet] init [--] [<path>...]
Junio C Hamano7d40f892009-06-13 12:49:50 -070016'git submodule' [--quiet] update [--init] [-N|--no-fetch] [--rebase]
Johan Herlandb13fd5c2009-08-19 03:45:23 +020017 [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
Jens Lehmann1c244f62009-08-13 21:32:50 +020018'git submodule' [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
Johan Herland15fc56a2009-08-19 03:45:22 +020019'git submodule' [--quiet] foreach [--recursive] <command>
David Aguilar2327f612008-08-24 12:43:37 -070020'git submodule' [--quiet] sync [--] [<path>...]
Lars Hjemli70c7ac22007-05-26 15:56:40 +020021
22
Petr Baudise38953a2008-07-16 20:44:12 +020023DESCRIPTION
24-----------
Petr Baudisc47f1022008-07-18 15:40:41 +020025Submodules allow foreign repositories to be embedded within
26a dedicated subdirectory of the source tree, always pointed
27at a particular commit.
Petr Baudise38953a2008-07-16 20:44:12 +020028
Petr Baudisc47f1022008-07-18 15:40:41 +020029They are not to be confused with remotes, which are meant mainly
30for branches of the same project; submodules are meant for
31different projects you would like to make part of your source tree,
32while the history of the two projects still stays completely
33independent and you cannot modify the contents of the submodule
34from within the main project.
35If you want to merge the project histories and want to treat the
36aggregated whole as a single project from then on, you may want to
37add a remote for the other project and use the 'subtree' merge strategy,
38instead of treating the other project as a submodule. Directories
39that come from both projects can be cloned and checked out as a whole
40if you choose to go that route.
Petr Baudise38953a2008-07-16 20:44:12 +020041
Petr Baudisc47f1022008-07-18 15:40:41 +020042Submodules are composed from a so-called `gitlink` tree entry
43in the main repository that refers to a particular commit object
44within the inner repository that is completely separate.
45A record in the `.gitmodules` file at the root of the source
46tree assigns a logical name to the submodule and describes
47the default URL the submodule shall be cloned from.
48The logical name can be used for overriding this URL within your
49local repository configuration (see 'submodule init').
50
51This command will manage the tree entries and contents of the
52gitmodules file for you, as well as inspect the status of your
53submodules and update them.
54When adding a new submodule to the tree, the 'add' subcommand
55is to be used. However, when pulling a tree containing submodules,
56these will not be checked out by default;
57the 'init' and 'update' subcommands will maintain submodules
58checked out and at appropriate revision in your working tree.
59You can briefly inspect the up-to-date status of your submodules
60using the 'status' subcommand and get a detailed overview of the
61difference between the index and checkouts using the 'summary'
62subcommand.
Petr Baudise38953a2008-07-16 20:44:12 +020063
64
Lars Hjemli70c7ac22007-05-26 15:56:40 +020065COMMANDS
66--------
Sven Verdoolaegeecda0722007-06-24 23:06:07 +020067add::
68 Add the given repository as a submodule at the given path
Mark Levedahlec05df32008-07-09 21:05:40 -040069 to the changeset to be committed next to the current
Cesar Eduardo Barros77ef80a2008-07-26 01:17:42 -030070 project: the current project is termed the "superproject".
Mark Levedahlec05df32008-07-09 21:05:40 -040071+
Jens Lehmann1414e572009-09-22 17:10:12 +020072This requires at least one argument: <repository>. The optional
73argument <path> is the relative location for the cloned submodule
74to exist in the superproject. If <path> is not given, the
75"humanish" part of the source repository is used ("repo" for
76"/path/to/repo.git" and "foo" for "host.xz:foo/.git").
Mark Levedahlec05df32008-07-09 21:05:40 -040077+
78<repository> is the URL of the new submodule's origin repository.
79This may be either an absolute URL, or (if it begins with ./
80or ../), the location relative to the superproject's origin
81repository.
82+
83<path> is the relative location for the cloned submodule to
84exist in the superproject. If <path> does not exist, then the
85submodule is created by cloning from the named URL. If <path> does
86exist and is already a valid git repository, then this is added
87to the changeset without cloning. This second form is provided
88to ease creating a new submodule from scratch, and presumes
89the user will later push the submodule to the given URL.
90+
91In either case, the given URL is recorded into .gitmodules for
92use by subsequent users cloning the superproject. If the URL is
93given relative to the superproject's repository, the presumption
94is the superproject and submodule repositories will be kept
95together in the same relative location, and only the
Markus Heidelberg04c8ce92008-12-19 13:14:18 +010096superproject's URL needs to be provided: git-submodule will correctly
Mark Levedahlec05df32008-07-09 21:05:40 -040097locate the submodule using the relative URL in .gitmodules.
Sven Verdoolaegeecda0722007-06-24 23:06:07 +020098
Lars Hjemli70c7ac22007-05-26 15:56:40 +020099status::
100 Show the status of the submodules. This will print the SHA-1 of the
101 currently checked out commit for each submodule, along with the
Thomas Rast0b444cd2010-01-10 00:33:00 +0100102 submodule path and the output of 'git describe' for the
Lars Hjemli70c7ac22007-05-26 15:56:40 +0200103 SHA-1. Each SHA-1 will be prefixed with `-` if the submodule is not
Nicolas Morey-Chaisemartin313ee0d2011-03-30 07:20:02 +0200104 initialized, `+` if the currently checked out submodule commit
Lars Hjemli70c7ac22007-05-26 15:56:40 +0200105 does not match the SHA-1 found in the index of the containing
Nicolas Morey-Chaisemartin313ee0d2011-03-30 07:20:02 +0200106 repository and `U` if the submodule has merge conflicts.
107 This command is the default command for 'git submodule'.
Johan Herland64b19ff2009-08-19 03:45:24 +0200108+
109If '--recursive' is specified, this command will recurse into nested
110submodules, and show their status as well.
Lars Hjemli70c7ac22007-05-26 15:56:40 +0200111
112init::
Petr Baudisc47f1022008-07-18 15:40:41 +0200113 Initialize the submodules, i.e. register each submodule name
114 and url found in .gitmodules into .git/config.
115 The key used in .git/config is `submodule.$name.url`.
116 This command does not alter existing information in .git/config.
117 You can then customize the submodule clone URLs in .git/config
Thomas Rastca768282010-01-07 17:49:12 +0100118 for your local setup and proceed to `git submodule update`;
119 you can also just use `git submodule update --init` without
Petr Baudisc47f1022008-07-18 15:40:41 +0200120 the explicit 'init' step if you do not intend to customize
121 any submodule locations.
Lars Hjemli70c7ac22007-05-26 15:56:40 +0200122
123update::
Lars Hjemli211b7f12007-06-06 11:13:02 +0200124 Update the registered submodules, i.e. clone missing submodules and
125 checkout the commit specified in the index of the containing repository.
Johan Herland42b49172009-06-03 00:59:12 +0200126 This will make the submodules HEAD be detached unless '--rebase' or
127 '--merge' is specified or the key `submodule.$name.update` is set to
128 `rebase` or `merge`.
Johannes Schindelinbe4d2c82008-05-16 11:23:03 +0100129+
130If the submodule is not yet initialized, and you just want to use the
131setting as stored in .gitmodules, you can automatically initialize the
132submodule with the --init option.
Johan Herlandb13fd5c2009-08-19 03:45:23 +0200133+
134If '--recursive' is specified, this command will recurse into the
135registered submodules, and update any nested submodules within.
Lars Hjemli70c7ac22007-05-26 15:56:40 +0200136
Ping Yin925e7f62008-03-11 21:52:18 +0800137summary::
138 Show commit summary between the given commit (defaults to HEAD) and
139 working tree/index. For a submodule in question, a series of commits
140 in the submodule between the given super project commit and the
Jens Lehmann1c244f62009-08-13 21:32:50 +0200141 index or working tree (switched by --cached) are shown. If the option
142 --files is given, show the series of commits in the submodule between
Lars Hjemlief92e1a2009-08-15 10:40:42 +0200143 the index of the super project and the working tree of the submodule
Jens Lehmann1c244f62009-08-13 21:32:50 +0200144 (this option doesn't allow to use the --cached option or to provide an
145 explicit commit).
Lars Hjemli70c7ac22007-05-26 15:56:40 +0200146
Mark Levedahl19a31f92008-08-10 19:10:04 -0400147foreach::
148 Evaluates an arbitrary shell command in each checked out submodule.
Ævar Arnfjörð Bjarmasonf030c962010-05-21 16:10:10 +0000149 The command has access to the variables $name, $path, $sha1 and
150 $toplevel:
Johan Herland1e7f2aa2009-08-16 03:10:08 +0200151 $name is the name of the relevant submodule section in .gitmodules,
Mark Levedahl19a31f92008-08-10 19:10:04 -0400152 $path is the name of the submodule directory relative to the
Ævar Arnfjörð Bjarmasonf030c962010-05-21 16:10:10 +0000153 superproject, $sha1 is the commit as recorded in the superproject,
154 and $toplevel is the absolute path to the top-level of the superproject.
Mark Levedahl19a31f92008-08-10 19:10:04 -0400155 Any submodules defined in the superproject but not checked out are
156 ignored by this command. Unless given --quiet, foreach prints the name
157 of each submodule before evaluating the command.
Johan Herland15fc56a2009-08-19 03:45:22 +0200158 If --recursive is given, submodules are traversed recursively (i.e.
159 the given shell command is evaluated in nested submodules as well).
Mark Levedahl19a31f92008-08-10 19:10:04 -0400160 A non-zero return from the command in any submodule causes
161 the processing to terminate. This can be overridden by adding '|| :'
162 to the end of the command.
163+
Miklos Vajna1c3acfc2009-06-28 14:55:45 +0200164As an example, +git submodule foreach \'echo $path {backtick}git
165rev-parse HEAD{backtick}'+ will show the path and currently checked out
166commit for each submodule.
Mark Levedahl19a31f92008-08-10 19:10:04 -0400167
David Aguilar2327f612008-08-24 12:43:37 -0700168sync::
169 Synchronizes submodules' remote URL configuration setting
170 to the value specified in .gitmodules. This is useful when
171 submodule URLs change upstream and you need to update your local
172 repositories accordingly.
173+
174"git submodule sync" synchronizes all submodules while
175"git submodule sync -- A" synchronizes submodule "A" only.
Mark Levedahl19a31f92008-08-10 19:10:04 -0400176
Lars Hjemli70c7ac22007-05-26 15:56:40 +0200177OPTIONS
178-------
Stephan Beyer32402402008-06-08 03:36:09 +0200179-q::
180--quiet::
Lars Hjemli70c7ac22007-05-26 15:56:40 +0200181 Only print error messages.
182
Stephan Beyer32402402008-06-08 03:36:09 +0200183-b::
184--branch::
Sven Verdoolaegeecda0722007-06-24 23:06:07 +0200185 Branch of repository to add as submodule.
186
Jens Lehmannd27b8762010-07-17 17:11:43 +0200187-f::
188--force::
Nicolas Morey-Chaisemartin9db31bd2011-04-01 11:42:03 +0200189 This option is only valid for add and update commands.
190 When running add, allow adding an otherwise ignored submodule path.
191 When running update, throw away local changes in submodules when
192 switching to a different commit.
Jens Lehmannd27b8762010-07-17 17:11:43 +0200193
Lars Hjemli70c7ac22007-05-26 15:56:40 +0200194--cached::
Ping Yin925e7f62008-03-11 21:52:18 +0800195 This option is only valid for status and summary commands. These
196 commands typically use the commit found in the submodule HEAD, but
197 with this option, the commit stored in the index is used instead.
198
Jens Lehmann1c244f62009-08-13 21:32:50 +0200199--files::
200 This option is only valid for the summary command. This command
201 compares the commit in the index with that in the submodule HEAD
202 when this option is used.
203
Stephan Beyer32402402008-06-08 03:36:09 +0200204-n::
205--summary-limit::
Ping Yin925e7f62008-03-11 21:52:18 +0800206 This option is only valid for the summary command.
207 Limit the summary size (number of commits shown in total).
Junio C Hamano51836e92008-04-12 18:34:39 -0700208 Giving 0 will disable the summary; a negative number means unlimited
Ping Yin925e7f62008-03-11 21:52:18 +0800209 (the default). This limit only applies to modified submodules. The
210 size is always limited to 1 for added/deleted/typechanged submodules.
Lars Hjemli70c7ac22007-05-26 15:56:40 +0200211
Fabian Franz31ca3ac2009-02-05 20:18:32 -0200212-N::
213--no-fetch::
214 This option is only valid for the update command.
215 Don't fetch new objects from the remote site.
216
Johan Herland42b49172009-06-03 00:59:12 +0200217--merge::
218 This option is only valid for the update command.
219 Merge the commit recorded in the superproject into the current branch
220 of the submodule. If this option is given, the submodule's HEAD will
221 not be detached. If a merge failure prevents this process, you will
222 have to resolve the resulting conflicts within the submodule with the
223 usual conflict resolution tools.
224 If the key `submodule.$name.update` is set to `merge`, this option is
225 implicit.
226
Peter Huttererca2cedb2009-04-24 09:06:38 +1000227--rebase::
228 This option is only valid for the update command.
229 Rebase the current branch onto the commit recorded in the
230 superproject. If this option is given, the submodule's HEAD will not
Ralf Wildenhues6a5d0b02010-01-31 14:24:39 +0100231 be detached. If a merge failure prevents this process, you will have
Peter Huttererca2cedb2009-04-24 09:06:38 +1000232 to resolve these failures with linkgit:git-rebase[1].
Johan Herland32948422009-06-03 08:27:06 +0200233 If the key `submodule.$name.update` is set to `rebase`, this option is
Peter Huttererca2cedb2009-04-24 09:06:38 +1000234 implicit.
235
Michael S. Tsirkind92a3952009-05-04 22:30:01 +0300236--reference <repository>::
237 This option is only valid for add and update commands. These
238 commands sometimes need to clone a remote repository. In this case,
239 this option will be passed to the linkgit:git-clone[1] command.
240+
241*NOTE*: Do *not* use this option unless you have read the note
242for linkgit:git-clone[1]'s --reference and --shared options carefully.
243
Johan Herland15fc56a2009-08-19 03:45:22 +0200244--recursive::
Johan Herland64b19ff2009-08-19 03:45:24 +0200245 This option is only valid for foreach, update and status commands.
Johan Herland15fc56a2009-08-19 03:45:22 +0200246 Traverse submodules recursively. The operation is performed not
247 only in the submodules of the current repo, but also
248 in any nested submodules inside those submodules (and so on).
249
Abhijit Menon-Senf448e242008-07-30 15:03:43 +0530250<path>...::
251 Paths to submodule(s). When specified this will restrict the command
Lars Hjemli70c7ac22007-05-26 15:56:40 +0200252 to only operate on the submodules found at the specified paths.
Mark Levedahlec05df32008-07-09 21:05:40 -0400253 (This argument is required with add).
Lars Hjemli70c7ac22007-05-26 15:56:40 +0200254
255FILES
256-----
Lars Hjemli211b7f12007-06-06 11:13:02 +0200257When initializing submodules, a .gitmodules file in the top-level directory
Lars Hjemli70c7ac22007-05-26 15:56:40 +0200258of the containing repository is used to find the url of each submodule.
Junio C Hamanoc4585702007-12-27 23:29:53 -0800259This file should be formatted in the same way as `$GIT_DIR/config`. The key
Dan McGee5162e692007-12-29 00:20:38 -0600260to each submodule url is "submodule.$name.url". See linkgit:gitmodules[5]
Junio C Hamano6fbe42c2007-12-16 22:03:21 -0800261for details.
Lars Hjemli70c7ac22007-05-26 15:56:40 +0200262
Lars Hjemli70c7ac22007-05-26 15:56:40 +0200263GIT
264---
Christian Couder9e1f0a82008-06-06 09:07:32 +0200265Part of the linkgit:git[1] suite