UP | HOME

git submodule

1. add another repo as a submodule

git submodule add -b <branch> git@github.com:<repo> <target_name>
  • The <target_name> is what the submodule directory will be called
  • The <branch> is which branch from the <repo> to grab

If you previously already have cloned the (parent) repo, then, to obtain the submodule, you should use:

git submodule update --init --recursive

2. commit and push to submodule

When you first get the submodule, it will be in a detached head state. In order to make pushes to the submodule repo, you should:

cd <submodule>
git checkout <branch>

3. remove submodule

git submodule deinit the_submodule
git rm the_submodule  

Created: 2024-07-15 Mon 01:28