git git-submodules

Pull latest changes for all git submodules


We’re using git submodules to manage a couple of large projects that have dependencies on many other libraries we’ve developed. Each library is a separate repo brought into the dependent project as a submodule. During development, we often want to just go grab the latest version of every dependent submodule.

How do I pull the latest changes for all git submodules?


  • git-deep should help with this.

    Jan 2, 2017 at 0:48

  • 13

    @Brad do you want to update your copies of submodules to the commit revs named in the master project; or do you want to pull the latest HEAD commit from every submodule? Most of the answers here address the former; many people want the latter.

    Feb 22, 2018 at 21:31

  • You can find this answer with Git flow with submodules helpful

    Feb 3 at 22:33


If it’s the first time you check-out a repo you need to use --init first:

git submodule update --init --recursive

For git 1.8.2 or above, the option --remote was added to support updating to latest tips of remote branches:

git submodule update --recursive --remote

This has the added benefit of respecting any “non default” branches specified in the .gitmodules or .git/config files (if you happen to have any, default is origin/master, in which case some of the other answers here would work as well).

For git 1.7.3 or above you can use (but the below gotchas around what update does still apply):

git submodule update --recursive


git pull --recurse-submodules

if you want to pull your submodules to latest commits instead of the current commit the repo points to.

See git-submodule(1) for details


  • 333

    Probably you should use git submodule update --recursive nowadays.

    – Jens Kohl

    Sep 30, 2011 at 14:12

  • 50

    Performance improvement: git submodule foreach "(git checkout master; git pull)&"

    Nov 7, 2011 at 13:27

  • 27

    update will update each submodule to the specified revision, not update it to the latest for that repository.

    Dec 18, 2012 at 20:56

  • 25

    Just to add, blindly sticking origin master at the end of this command might have unexpected results if some of your submodules are tracking a different branch or location name of that particular submodule. Obvious to some, but probably not to everyone.

    Jul 23, 2014 at 18:00

  • 65

    Just to clarify for everyone. git submodule update --recursive looks to see which revision the parent repository has stored for each submodule, then checks out that revision in each submodule. It does NOT pull the latest commits for each submodule. git submodule foreach git pull origin master or git pull origin master --recurse-submodules is what you want if you intend to update each submodule to the latest from their origin repositories. Only then will you get pending changes in the parent repo with updated revision hashes for submodules. Check those in and you’re good.

    – Chev

    Oct 22, 2015 at 16:14


git pull --recurse-submodules --jobs=10

a feature git first learned in 1.8.5.

Until the bug is fixed, for the first time you do need to run

git submodule update –init –recursive


  • 34

    upvoted, i use this: alias update_submodules=’git pull –recurse-submodules && git submodule update’

    – Stephen C

    Dec 6, 2011 at 22:41

  • 4

    This works if the submodules have already been pulled at least once but for submodules that have never been checked out, see gahooa’s answer below.

    Jan 24, 2013 at 4:11

  • 10

    This will pull up to the version the top repo specifies; it does NOT pull HEAD. For example if TopRepo specifies a version 2 behind HEAD for SubRepo, this will pull SubRepo with that version that’s 2 behind. Other answers here pull HEAD in SubRepo.

    Jun 12, 2014 at 17:09

  • 15

    Note that neither git pull --recurse-submodules nor git submodule update --recursive does not initialize newly added submodules. To initialize them you need run git submodule update --recursive --init. Quote from manual: If the submodule is not yet initialized, and you just want to use the setting as stored in .gitmodules, you can automatically initialize the submodule with the –init option.

    Mar 2, 2016 at 22:59

  • 2

    maybe add a hint to git submodule update --recursive --remote which also updates the submodules to the remote latest revision instead of the stored SHA-1.

    – Hanno S.

    Jun 17, 2016 at 10:59


On init running the following command:

git submodule update --init --recursive

from within the git repo directory, works best for me.

This will pull all latest including submodules.


git - the base command to perform any git command
    submodule - Inspects, updates and manages submodules.
        update - Update the registered submodules to match what the superproject
        expects by cloning missing submodules and updating the working tree of the
        submodules. The "updating" can be done in several ways depending on command
        line options and the value of submodule.<name>.update configuration variable.
            --init without the explicit init step if you do not intend to customize
            any submodule locations.
            --recursive is specified, this command will recurse into the registered
            submodules, and update any nested submodules within.

After this you can just run:

git submodule update --recursive

from within the git repo directory, works best for me.

This will pull all latest including submodules.


  • 11

    Yes — the highest voted answer was the best way to do it in ’09, but this is definitely simpler and more intuitive now.

    Aug 28, 2015 at 17:52

  • 2

    @MichaelScottCuthbert thanks, i’m sure in another 3 years this command will be crazy too

    – abc123

    Aug 28, 2015 at 19:28

  • 8

    Nevertheless, this does not checkout the latest revision from the submodule, only the latest revision that the parent is tracking.

    Apr 5, 2016 at 4:44

  • 5

    @NathanOsman which is what you want…you will end up with broken code by not following the parents revision tracking. If you are the maintainer of the parent you can update those yourself and commit them.

    – abc123

    Apr 6, 2016 at 19:39

  • 4

    Yes, but from my understanding, that isn’t what the OP wanted.

    Apr 6, 2016 at 23:31