docs:git:submodules

submodules

git submodules are entire projects that are incorporated into another project. These submodules maintain their own version history. The most important point to understand is that when working with a submodule, you are only doing the following:

  1. telling the master project what to call the submodule (a directory name)
  2. telling the master project where to pull this submodule project from (a repo location)
  3. telling the master project which SHA-1 hash (revision number) of this submodule will be used in the master project
git submodule add /path/to/submodule.git path/for/submodule/in/your/project
(adds a folder for the submodule, and creates .gitmodules at the root of your project)

git submodule init
(adds the submodule reference info from .gitmodules to your .git/config)

git submodule update
(checks out the submodule)
  1. Delete the relevant line from the .gitmodules file.
  2. Delete the relevant section from .git/config.
  3. Run git rm –cached path_to_submodule (no trailing slash).
  4. Commit and delete the now untracked submodule files.

Source: http://stackoverflow.com/questions/1260748/how-do-i-remove-a-git-submodule

The easiest way to clone a project with submodules is to use the --recursive flag, which initializes and checks out all submodules.

git clone --recursive /path/to/repo.git

or

git clone --recursive /path/to/repo.git myproject
  • docs/git/submodules.txt
  • Last modified: 2011/07/21 11:53
  • by billh