Usage scenarios

Split the project. As the project gets bigger and bigger, we want the sub-modules to be managed separately and maintained by a dedicated person. This can only be done using git subModules.

Common commands

Git submodule add <repository> path git submodule init git submodule init Git submodule update git submodule updateCopy the code

use

Adding submodules

Git submodule add path

Clone submodule

Git clone — Recursive clone. If the parent project is cloned, you can use git subModule init to initialize the list of child projects and git submodule update to update the latest child project.

Update submodules

Git submodule foreach Git pull if the submodule is newer than.gitModules, you can update.gitModules using git submodule foreach Git pull.

The versions of the child modules in the parent project are identified by the COMMIT ID, so.gitModules needs to be updated.

Deleting a Submodule

Git rm –cached first, then delete the records in the corresponding directory, in.gitmodules files, and in.git/cofig. Submit it to the remote server and you can delete it.

Note:

Git rm –cached does not end with /.

Example Modify submodule configuration information

As with deleting, you need to change the URL values in both.gitModules and.git/config files, and then execute git subModule sync to synchronize them, and then commit them to a remote location.

This article was originally posted at www.zucchiniy.cn