Maintaining submodules in a Git repository

I'm learning new Git tricks thanks to Damien and want to make sure I don't forget any of them, so I'm introducing a new Git tag here on the blog to start writing these down.

I'm working on a project with the team in Paris for the week, and the structure of the project is such that we maintain a main Git repository that pulls in Drupal and a variety of contributed modules using git submodules. To build the full project locally, I first clone our main repository and then issue git submodule init / update commands to get the proper versions of our submodules.

Now, I'm still learning the ropes with Git terminology and repository management, but from what I understand, a submodule folder points to the URL of the repository and a precise commit. It won't automatically track a branch, so when the remote repository has new commits or you make new commits in your submodule repositories, you have to tell the main repository something has changed.

First you would change directories into the submodule and either pull in the new commits or perhaps make your changes, commit them, and push them upstream. Then you would change back into the main repository directory and perform a git add on the submodule directory. Committing this will update the main repository to point to the new current commit in the submodule directory. Pushing this upstream will ensure that everyone else on the project can pull the change and use git submodule update to pull the new commits into their local submodule directories.

Pretty straightforward I suppose?



Hehe, yes, a straightforward concept yet I have yet to find a straightforward example of how to do this :P. I've resorted to including ".git" in my .gitignore file and just assuming that all of the juicy .git folders are stuck in my sandbox. It's not very nice when other developers checkout my repositories though :(.