Git submodules

Git allows you to have repos inside your repo using submodules. Each submodule has its own git database and thus its own history. The main project tracks which version of the submodule is being used. So, when you update a submodule, the main project records a change in version hash for that submodule.

More details can be found in the git manual.

Creating

To clone a repo as a submodule, first go to the main git repo directory. Then:

git submodule add URL

Using

Once you have a submodule, you can issue git commands in the submodule directory:

cd submodule_dir
git pull    # update submodule repo
git add xxx # add file to submodule
git commit  # commit to submodule
git push    # push to submodule remote

As you make change to the submodule, the main repo tracks the commit version of the submodule. No actual data is tracked.

Cloning submodule projects

When you clone a submodule project, no submodule data is included. Instead, the main repo tracks the submodule revision needed and creates an empty directory for the submodule. You are responsible for pulling each submodule's data.

You can pull submodules like this:

cd submodule_dir
git submodule init
git submoudle update