Git Submodule Tips
I seem to have a never-ending struggle with git submodules. Today, I need to add some new features to one of my submodules in a non-ISLE project, but I’ve elected to post this here because this blog is relatively easy to search. I also feel fortunate to have found Mastering Git Submodules from Christophe Porteneuve.
So, what I need to do now is update some submodule code, commit, and push that change back to its remote. I will also want to subsequentmly update a pair of projects that use the submodule so they are referencing the newest submodule code.
In case Christophe’s post ever disappers, here’s the key portion that I need right now…
Updating a Submodule Inside Container Code
- git submodule update –remote –rebase – path/to/module
- cd path/to/module
- Local work, testing, eventually staging
- git commit -am “Update to central submodule: blah blah”
- git push
- cd -
- git commit -am “Updated submodule X to: blah blah”
Updating a Project To Use Latest Submodule Code
Shortly after updating my submodule code and pushing that to GitHub, I naturally wanted to update one or two of my projects to use that latest version of the submodule. Hmmm, what’s the best way to do that? Luckily I found this reply and the guidance there worked nicely. In case the post or reply is ever lost, here’s the important parts:
The git submodule update command actually tells git that you simply want your submodules to each check out the commit already mentioned in the index of the superproject.
If you want to update your submodules to the most recent commit available from their remote, you’ll try this directly within the submodules.
So in summary:
# Get the submodule initially
git submodule add ssh://bla submodule_dir
git submodule init
# Time passes, submodule upstream is updated and you now want to update
# Change to the submodule directory
cd submodule_dir
# Checkout desired branch
git checkout master
# Update
git pull
# Get back to your project root
cd...
# now the submodules are in the state you wanted, so
git commit -am "Pulled down update to submodule_dir"
And that’s a wrap. Hope this helps others as much as it helped me.