User Tools

Site Tools


git:git-submodules

This is an old revision of the document!


Back to git main page

If you clone a git repo inside you git, the best way to handle it is to use modules (sub modules). To define it you can use :

git submodule add <git URL> <path>

Where git URL is the URL of the git repo and path is where this git repo is stored in the main git.

For example we are working in the git repo submodules_main and we would like to use an external git at URL https://gitlab.com/bnzr/python_control_coppeliasim.git

mkdir external
git clone https://gitlab.com/bnzr/python_control_coppeliasim.git 
git submodule add https://gitlab.com/bnzr/python_control_coppeliasim.git external/python_control_coppeliasim/

We can list the submodules with :

git submodule foreach --quiet 'echo $name'

Information on submodules can be found in .gitmodules and .git/config of the main project git

If we add the changes, commit and push , the content of submodules will not been added in the main project git, but information on how to retrieve it will be stored. In our example we push the changes :

git add --all
git commit -m "add python_control_coppeliasim external git repo"
git push

In another computer we can clone the main project repo :

git/git-submodules.1683038397.txt.gz · Last modified: 2023/05/02 16:39 by admin