Update submodule

First time need to init the submodule.

git submodule update --recursive --remote --init PATH

otherwise
git submodule update --recursive --remote

In this post, I noted for setup/update git submodule. In some scenarios, we developed in a project, which depends on some other library. If we want to separately version controlling both of them, git submodule is a good tool for that.

For example, I use Hexo to manage my blog, and in the repository there is a themes module to setup the blog theme.

Add submodule

cd BLOG_DIR
git submodule add GIT_URL themes/THEME_NAME

Suppose someone else update and push the submodule in the remote repository, we may need to update the submodule.

Update submodule

First time need to init the submodule.

git submodule update --recursive --remote --init PATH

otherwise
git submodule update --recursive --remote

Sometimes, we may encounter some problem of adding submodule, i.e. 'projectfolder' already exists in the index. Here is a way to fix it:

Fix issue of adding submodule

git rm --cached projectfolder

References:
Git submodule
Update submodule
Fix submodule issue