Documentation / git-submodule.txton commit Merge branch 'ml/submodule-foreach' (5630fea)
   1git-submodule(1)
   2================
   3
   4NAME
   5----
   6git-submodule - Initialize, update or inspect submodules
   7
   8
   9SYNOPSIS
  10--------
  11[verse]
  12'git submodule' [--quiet] add [-b branch] [--] <repository> <path>
  13'git submodule' [--quiet] status [--cached] [--] [<path>...]
  14'git submodule' [--quiet] init [--] [<path>...]
  15'git submodule' [--quiet] update [--init] [--] [<path>...]
  16'git submodule' [--quiet] summary [--summary-limit <n>] [commit] [--] [<path>...]
  17'git submodule' [--quiet] foreach <command>
  18
  19
  20DESCRIPTION
  21-----------
  22Submodules allow foreign repositories to be embedded within
  23a dedicated subdirectory of the source tree, always pointed
  24at a particular commit.
  25
  26They are not to be confused with remotes, which are meant mainly
  27for branches of the same project; submodules are meant for
  28different projects you would like to make part of your source tree,
  29while the history of the two projects still stays completely
  30independent and you cannot modify the contents of the submodule
  31from within the main project.
  32If you want to merge the project histories and want to treat the
  33aggregated whole as a single project from then on, you may want to
  34add a remote for the other project and use the 'subtree' merge strategy,
  35instead of treating the other project as a submodule. Directories
  36that come from both projects can be cloned and checked out as a whole
  37if you choose to go that route.
  38
  39Submodules are composed from a so-called `gitlink` tree entry
  40in the main repository that refers to a particular commit object
  41within the inner repository that is completely separate.
  42A record in the `.gitmodules` file at the root of the source
  43tree assigns a logical name to the submodule and describes
  44the default URL the submodule shall be cloned from.
  45The logical name can be used for overriding this URL within your
  46local repository configuration (see 'submodule init').
  47
  48This command will manage the tree entries and contents of the
  49gitmodules file for you, as well as inspect the status of your
  50submodules and update them.
  51When adding a new submodule to the tree, the 'add' subcommand
  52is to be used.  However, when pulling a tree containing submodules,
  53these will not be checked out by default;
  54the 'init' and 'update' subcommands will maintain submodules
  55checked out and at appropriate revision in your working tree.
  56You can briefly inspect the up-to-date status of your submodules
  57using the 'status' subcommand and get a detailed overview of the
  58difference between the index and checkouts using the 'summary'
  59subcommand.
  60
  61
  62COMMANDS
  63--------
  64add::
  65        Add the given repository as a submodule at the given path
  66        to the changeset to be committed next to the current
  67        project: the current project is termed the "superproject".
  68+
  69This requires two arguments: <repository> and <path>.
  70+
  71<repository> is the URL of the new submodule's origin repository.
  72This may be either an absolute URL, or (if it begins with ./
  73or ../), the location relative to the superproject's origin
  74repository.
  75+
  76<path> is the relative location for the cloned submodule to
  77exist in the superproject. If <path> does not exist, then the
  78submodule is created by cloning from the named URL. If <path> does
  79exist and is already a valid git repository, then this is added
  80to the changeset without cloning. This second form is provided
  81to ease creating a new submodule from scratch, and presumes
  82the user will later push the submodule to the given URL.
  83+
  84In either case, the given URL is recorded into .gitmodules for
  85use by subsequent users cloning the superproject. If the URL is
  86given relative to the superproject's repository, the presumption
  87is the superproject and submodule repositories will be kept
  88together in the same relative location, and only the
  89superproject's URL need be provided: git-submodule will correctly
  90locate the submodule using the relative URL in .gitmodules.
  91
  92status::
  93        Show the status of the submodules. This will print the SHA-1 of the
  94        currently checked out commit for each submodule, along with the
  95        submodule path and the output of 'git-describe' for the
  96        SHA-1. Each SHA-1 will be prefixed with `-` if the submodule is not
  97        initialized and `+` if the currently checked out submodule commit
  98        does not match the SHA-1 found in the index of the containing
  99        repository. This command is the default command for 'git-submodule'.
 100
 101init::
 102        Initialize the submodules, i.e. register each submodule name
 103        and url found in .gitmodules into .git/config.
 104        The key used in .git/config is `submodule.$name.url`.
 105        This command does not alter existing information in .git/config.
 106        You can then customize the submodule clone URLs in .git/config
 107        for your local setup and proceed to 'git submodule update';
 108        you can also just use 'git submodule update --init' without
 109        the explicit 'init' step if you do not intend to customize
 110        any submodule locations.
 111
 112update::
 113        Update the registered submodules, i.e. clone missing submodules and
 114        checkout the commit specified in the index of the containing repository.
 115        This will make the submodules HEAD be detached.
 116+
 117If the submodule is not yet initialized, and you just want to use the
 118setting as stored in .gitmodules, you can automatically initialize the
 119submodule with the --init option.
 120
 121summary::
 122        Show commit summary between the given commit (defaults to HEAD) and
 123        working tree/index. For a submodule in question, a series of commits
 124        in the submodule between the given super project commit and the
 125        index or working tree (switched by --cached) are shown.
 126
 127foreach::
 128        Evaluates an arbitrary shell command in each checked out submodule.
 129        The command has access to the variables $path and $sha1:
 130        $path is the name of the submodule directory relative to the
 131        superproject, and $sha1 is the commit as recorded in the superproject.
 132        Any submodules defined in the superproject but not checked out are
 133        ignored by this command. Unless given --quiet, foreach prints the name
 134        of each submodule before evaluating the command.
 135        A non-zero return from the command in any submodule causes
 136        the processing to terminate. This can be overridden by adding '|| :'
 137        to the end of the command.
 138+
 139As an example, "git submodule foreach 'echo $path `git rev-parse HEAD`' will
 140show the path and currently checked out commit for each submodule.
 141
 142
 143OPTIONS
 144-------
 145-q::
 146--quiet::
 147        Only print error messages.
 148
 149-b::
 150--branch::
 151        Branch of repository to add as submodule.
 152
 153--cached::
 154        This option is only valid for status and summary commands.  These
 155        commands typically use the commit found in the submodule HEAD, but
 156        with this option, the commit stored in the index is used instead.
 157
 158-n::
 159--summary-limit::
 160        This option is only valid for the summary command.
 161        Limit the summary size (number of commits shown in total).
 162        Giving 0 will disable the summary; a negative number means unlimited
 163        (the default). This limit only applies to modified submodules. The
 164        size is always limited to 1 for added/deleted/typechanged submodules.
 165
 166<path>...::
 167        Paths to submodule(s). When specified this will restrict the command
 168        to only operate on the submodules found at the specified paths.
 169        (This argument is required with add).
 170
 171FILES
 172-----
 173When initializing submodules, a .gitmodules file in the top-level directory
 174of the containing repository is used to find the url of each submodule.
 175This file should be formatted in the same way as `$GIT_DIR/config`. The key
 176to each submodule url is "submodule.$name.url".  See linkgit:gitmodules[5]
 177for details.
 178
 179
 180AUTHOR
 181------
 182Written by Lars Hjemli <hjemli@gmail.com>
 183
 184GIT
 185---
 186Part of the linkgit:git[1] suite