Add submodule

Add a submodule to the main project.

Execute in the main project
git submodule add <submodule-repository> [<path>]

For example, add components to main-project
# cd main-project/
# git submodule add [email protected]/components.git components
Copy the code

Clone main project and sub-modules

Git clone does not clone submodules directly. There are two ways to clone main project code and submodule code.

A:

git clone <main-project-repository>
git submodule init
git submodule update
Copy the code

Method 2:

git clone <repository> --recurse-submodules
Copy the code

Pull the submodule code

The submodule remote code has been updated and needs to be pulled from the main project for the remote submodule. After the submodule code is pulled locally, the main project needs to be submitted.

There are two ways to pull submodule code.

A:

# Go to the submodule directory and pull the code
cd components
git checkout master
git pull
Copy the code

Method 2:

# Enter the main project
cd main-project

Pull remote submodule code locally
git submodule update --remote
Copy the code

After the submodule code is pulled locally, it is equivalent to modifying the record saved in the main project, so you need to commit the main project.

Pull main project code and submodule code

The master project remote code has been updated. Using Git pull code in the master project will only pull records from the master project, not submodule code. There are two ways to pull submodule code.

A:

# In the main project
cd main-project

Update the main project code
git pull [--rebase]

Update the local submodule code according to the main project record
git submodule update
Copy the code

Method 2:

cd main-project

git pull --recurse-submodules
Copy the code

Deleting a Submodule

cd main-project

# Unload submodules
# git submodule deinit components
git submodule deinit <path>

Delete the submodule folder
# git rm components
git rm <path>

Git /modules/[submodule-name
Git /config: delete [submodule-name] from. Git /config
Copy the code