Update Submodules with Git

By  on  

Git submodules seem to confuse people and I can probably count myself in that group of people that are confused.  Their code is kind of part of the codebase, kind of isn't.  Pulling the latest code from the overall project doesn't pull the updated submodule code, so sometimes you get errors and don't know what's going on.  To ensure your submodules are always up to date, run this via the command line:

git submodule update --init --recursive

This command ensure your existing submodules are current as well as adds new submodule code whenever appropriate.  I like to run this at least once a day just to make sure my code is always up to date.  You never know what some of your collaborators have contributed (if you work in a team setting), so running this daily is useful!

Recent Features

  • By
    Facebook Open Graph META Tags

    It's no secret that Facebook has become a major traffic driver for all types of websites.  Nowadays even large corporations steer consumers toward their Facebook pages instead of the corporate websites directly.  And of course there are Facebook "Like" and "Recommend" widgets on every website.  One...

  • By
    CSS @supports

    Feature detection via JavaScript is a client side best practice and for all the right reasons, but unfortunately that same functionality hasn't been available within CSS.  What we end up doing is repeating the same properties multiple times with each browser prefix.  Yuck.  Another thing we...

Incredible Demos

  • By
    Multiple File Upload Input

    More often than not, I find myself wanting to upload more than one file at a time.  Having to use multiple "file" INPUT elements is annoying, slow, and inefficient.  And if I hate them, I can't imagine how annoyed my users would be.  Luckily Safari, Chrome...

  • By
    Telephone Link Protocol

    We've always been able to create links with protocols other than the usual HTTP, like mailto, skype, irc ,and more;  they're an excellent convenience to visitors.  With mobile phone browsers having become infinitely more usable, we can now extend that convenience to phone numbers: The tel...

Discussion

  1. While this is definitely a useful command, it’s worth noting that updating your submodules basically just checks out the revision as defined in the repository. If you’re maintaining a project that uses submodules, this won’t get the latest code for that submodule, so much as it just ensures that the submodule is on the commit as defined.

    For example, I maintain all of my dotfiles in a Git repository, which includes several submodules (Vim plugins, mostly). This command doesn’t actually update the submodules to the latest revision on their branch. If I want to go into each submodule and pull the latest code for each (which can be horribly risky, caveat emptor), I can do something like this:

    git submodule foreach ‘git checkout master && git pull origin master’

    That will go through each of my submodules, ensuring that they are on the latest master branch. That may not be the desired or best behavior, but it is something I learned about with regards to `git submodule update`.

  2. Hi!
    I’m very interested in git’s submodules but I can’t find a tutorial that I can understand properly

    Could you address this? (or at least point me to your reference tutorial)

    Thanks a lot!

  3. Newton

    Why not create a Git hook for this?

    You could use post-checkout & post-merge to automatically fire this on every branch checkout or pull, respectively.

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!