If I have a project that contains a number of submodules, and I switch to a new branch, from the parent directory, will it include those submodules in my new branch? How will they be affected?
Asked
Active
Viewed 65 times
1 Answers
1
A submodule is a SHA1 entry recorded in the index as a special entry 160000.
When you change branches, your index will reflect the SHA1 of those same submodules are recorded in that new branch.
A git submodule update --init --recursive
will update said submodules.
That means you can have different version of the same submodule, as referenced by different branches.
Remmeber:
- Whatever branch you chose in the parent repo, the submodules are always in a detached HEAD mode (unless you go in a submodule, and checkout a branch there)
- You need to configure a submodule a certain way (see "
git submodule
tracking latest") in order for it to follow its own upstream branch (you can convert an existing submodule to that mode).
And you would need to make asubmodule update --remote
from the parent repo in order to trigger a fetch from the submodule configured to follow a branch.