We are moving our (huge) project to git and we are thinking about using submodules. Our plan is to have three different heads in the superproject: release,stable,latest. The project leads will handle the release and stable branches. They will move the submodules as required.
The issue is the "latest" head. We would like the superproject "latest" head to track the master branches of all the submodules (automatically). And also it would be great if it would show the history of all commits to the submodule.
I have looked at gitslave, but it is not quite what we want. Any suggestions?
Update March 2013
Git 1.8.2 added the possibility to track branches.
git submodule" started learning a new mode to integrate with the tip of the remote branch (as opposed to integrating with the commit recorded in the superproject's gitlink).
# add submodule to track master branch git submodule add -b master [URL to Git repo]; # update your submodule git submodule update --remote
See also the Vogella's tutorial on submodules.
See "How to make an existing submodule track a branch" (if you had a submodule already present you wish now would track a branch)
git submodule add -b . [URL to Git repo]; ^^^
A special value of
.is used to indicate that the name of the branch in the submodule should be the same name as the current branch in the current repository.
submodule add: If
--branchis given, record it in
This allows you to easily record a
.gitmoduleswhen you add a new submodule. With this patch,
$ git submodule add -b <branch> <repository> [<path>] $ git config -f .gitmodules submodule.<path>.branch <branch>
$ git submodule add -b <branch> <repository> [<path>]
This means that future calls to
$ git submodule update --remote ...
will get updates from the same branch that you used to initialize the submodule, which is usually what you want.
Signed-off-by: W. Trevor King
Original answer (February 2012):
A submodule is a single commit referenced by a parent repo.
Since it is a Git rpeo on its own, the "history of all commits" is accessible through a
git log within that submodule.
So for a parent to track automatically the latest commit of a given branch of a submodule, it would need to:
It is a little annoying to make changes to the submodule due to the requirement to check out onto the correct submodule branch, make the change, commit, and then go into the superproject and commit the commit (or at least record the new location of the submodule).
Other alternatives are detailed here.