Easy way to pull latest of all git submodulesHow to use git submodulesHow to remove and re-fetch all git submodules?How to update all git submodules to latest commit?Run git pull over all subdirectoriesGit diff says subproject is dirtygit submodule tracking latestRecursive Git push/pull?How to pull a new submoduleHow do I get `git clone --recursive` to recreate submodules' remotes and branches?git submodule commit/push/pullHow to clone all remote branches in Git?What is the difference between 'git pull' and 'git fetch'?How to change the remote repository for a git submodule?How do I force “git pull” to overwrite local files?How do I revert all local changes in Git managed project to previous state?How can I specify a branch/tag when adding a Git submodule?How to “git clone” including submodules?What is the best (and safest) way to merge a Git branch into master?Update Git submodule to latest commit on originHow to fetch all Git branches

Composing fill in the blanks

Convert graph format for Mathematica graph functions

Can I attune a Circlet of Human Perfection to my animated skeletons to allow them to blend in and speak?

What are the closest international airports in different countries?

Complexity of verifying optimality in (mixed) integer programming

Piece of chess engine, which accomplishes move generation

Semen retention is a important thing in Martial arts?

What is the reason for cards stating "Until end of turn, you don't lose this mana as steps and phases end"?

Complaints from (junior) developers against solution architects: how can we show the benefits of our work and improve relationships?

What is the German equivalent of the proverb 水清ければ魚棲まず (if the water is clear, fish won't live there)?

Why was the LRV's speed gauge displaying metric units?

Can Lightning Lure be used to knock out a creature like a magical Taser?

If you inherit a Roth 401(k), is it taxed?

Why is softmax function used to calculate probabilities although we can divide each value by the sum of the vector?

Is SecureRandom.ints() secure?

What Marvel character has this 'W' symbol?

Exploiting the delay when a festival ticket is scanned

Was Donald Trump at ground zero helping out on 9-11?

Why did some Apollo missions carry a grenade launcher?

GNU sort stable sort when sort does not know sort order

Why force the nose of 737 Max down in the first place?

My employer is refusing to give me the pay that was advertised after an internal job move

How to efficiently shred a lot of cabbage?

Should I accept an invitation to give a talk from someone who might review my proposal?



Easy way to pull latest of all git submodules


How to use git submodulesHow to remove and re-fetch all git submodules?How to update all git submodules to latest commit?Run git pull over all subdirectoriesGit diff says subproject is dirtygit submodule tracking latestRecursive Git push/pull?How to pull a new submoduleHow do I get `git clone --recursive` to recreate submodules' remotes and branches?git submodule commit/push/pullHow to clone all remote branches in Git?What is the difference between 'git pull' and 'git fetch'?How to change the remote repository for a git submodule?How do I force “git pull” to overwrite local files?How do I revert all local changes in Git managed project to previous state?How can I specify a branch/tag when adding a Git submodule?How to “git clone” including submodules?What is the best (and safest) way to merge a Git branch into master?Update Git submodule to latest commit on originHow to fetch all Git branches






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1652















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.



Does git have a built in command to do this? If not, how about a Windows batch file or similar that can do it?










share|improve this question


























  • git-deep should help with this.

    – Mathew Kurian
    Jan 2 '17 at 0:48






  • 4





    @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.

    – chrisinmtown
    Feb 22 '18 at 21:31

















1652















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.



Does git have a built in command to do this? If not, how about a Windows batch file or similar that can do it?










share|improve this question


























  • git-deep should help with this.

    – Mathew Kurian
    Jan 2 '17 at 0:48






  • 4





    @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.

    – chrisinmtown
    Feb 22 '18 at 21:31













1652












1652








1652


667






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.



Does git have a built in command to do this? If not, how about a Windows batch file or similar that can do it?










share|improve this question
















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.



Does git have a built in command to do this? If not, how about a Windows batch file or similar that can do it?







git git-submodules






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 11:12









Paul Floyd

2,7342 gold badges20 silver badges32 bronze badges




2,7342 gold badges20 silver badges32 bronze badges










asked Jun 23 '09 at 1:05









Brad RobinsonBrad Robinson

17.1k15 gold badges46 silver badges73 bronze badges




17.1k15 gold badges46 silver badges73 bronze badges















  • git-deep should help with this.

    – Mathew Kurian
    Jan 2 '17 at 0:48






  • 4





    @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.

    – chrisinmtown
    Feb 22 '18 at 21:31

















  • git-deep should help with this.

    – Mathew Kurian
    Jan 2 '17 at 0:48






  • 4





    @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.

    – chrisinmtown
    Feb 22 '18 at 21:31
















git-deep should help with this.

– Mathew Kurian
Jan 2 '17 at 0:48





git-deep should help with this.

– Mathew Kurian
Jan 2 '17 at 0:48




4




4





@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.

– chrisinmtown
Feb 22 '18 at 21:31





@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.

– chrisinmtown
Feb 22 '18 at 21:31












19 Answers
19






active

oldest

votes


















2184














If it's the first time you checkout 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


or:



git pull --recurse-submodules


if you want to pull your submodules to latest commits intead of what the repo points to.



See git-submodule(1) for details






share|improve this answer






















  • 285





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

    – Jens Kohl
    Sep 30 '11 at 14:12






  • 34





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

    – Bogdan Gusiev
    Nov 7 '11 at 13:27







  • 15





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

    – Peter DeWeese
    Dec 18 '12 at 20:56






  • 21





    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.

    – Nathan Hornby
    Jul 23 '14 at 18:00







  • 25





    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 '15 at 16:14



















601














If you need to pull stuff for submodules into your submodule repositories use



git pull --recurse-submodules



a feature git first learned in 1.7.3.




But this will not checkout proper commits(the ones your master repository points to) in submodules



To checkout proper commits in your submodules you should update them after pulling using



git submodule update --recursive --remote





share|improve this answer






















  • 29





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

    – Stephen C
    Dec 6 '11 at 22:41







  • 3





    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.

    – Matt Browne
    Jan 24 '13 at 4:11






  • 7





    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.

    – Chris Moschini
    Jun 12 '14 at 17:09






  • 11





    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.

    – patryk.beza
    Mar 2 '16 at 22:59







  • 1





    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 '16 at 10:59


















369














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.



Explained



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.






share|improve this answer






















  • 10





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

    – Michael Scott Cuthbert
    Aug 28 '15 at 17:52






  • 2





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

    – abc123
    Aug 28 '15 at 19:28






  • 3





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

    – Nathan Osman
    Apr 5 '16 at 4:44







  • 3





    @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 '16 at 19:39






  • 2





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

    – Nathan Osman
    Apr 6 '16 at 23:31


















302














Note: This is from 2009 and may have been good then but there are better options now.



We use this. It's called git-pup:



#!/bin/bash
# Exists to fully update the git repo that you are sitting in...

git pull && git submodule init && git submodule update && git submodule status


Just put it in a suitable bin directory (/usr/local/bin). If on Windows, you may need to modify the syntax to get it to work :)



Update:



In response to the comment by the original author about pulling in all of the HEADs of all of the submodules -- that is a good question.



I am pretty sure that git does not have a command for this internally. In order to do so, you would need to identify what HEAD really is for a submodule. That could be as simple as saying master is the most up to date branch, etc...



Following this, create a simple script that does the following:



  1. check git submodule status for "modified" repositories. The first character of the output lines indicates this. If a sub-repo is modified, you may NOT want to proceed.

  2. for each repo listed, cd into it's directory and run git checkout master && git pull. Check for errors.

  3. At the end, I suggest you print a display to the user to indicate the current status of the submodules -- perhaps prompt them to add all and commit?

I'd like to mention that this style is not really what git submodules were designed for. Typically, you want to say "LibraryX" is at version "2.32" and will stay that way until I tell it to "upgrade".



That is, in a sense, what you are doing with the described script, but just more automatically. Care is required!



Update 2:



If you are on a windows platform, you may want to look at using Python to implement the script as it is very capable in these areas. If you are on unix/linux, then I suggest just a bash script.



Need any clarifications? Just post a comment.






share|improve this answer



























  • I don't think that's what I want. Won't that pull the version of the submodules that the super-project was last committed with. I want to pull the head version of all the submodules.

    – Brad Robinson
    Jun 23 '09 at 2:30






  • 3





    This works great, and works not only to update the submodules but also to fetch them for the first time if that's what you need.

    – Matt Browne
    Jan 24 '13 at 4:12











  • I'm just getting "There is no tracking information for the current branch. Please specify which branch you want to merge with." No matter what I try :/

    – Nathan Hornby
    Aug 4 '14 at 9:45






  • 7





    Why not create an alias for it? git config --global alias.pup '!git pull && git submodule init && git submodule update && git submodule status' and then use it as git pup without any scripting.

    – fracz
    Feb 11 '16 at 21:40











  • Thank you, for some reason even though I have git 1.9.1 I had to perform git submodule init after first pull that had submodules included, so that everything would start working properly.

    – Ben Usman
    May 12 '16 at 21:25


















154














Henrik is on the right track. The 'foreach' command can execute any arbitrary shell script. Two options to pull the very latest might be,



git submodule foreach git pull origin master


and,



git submodule foreach /path/to/some/cool/script.sh


That will iterate through all initialized submodules and run the given commands.






share|improve this answer
































    143














    The following worked for me on Windows.



    git submodule init
    git submodule update





    share|improve this answer




















    • 5





      This clearly is not what the OP asked for. It will only update to the associated submodule commit and not the latest one.

      – Patrick
      Oct 29 '11 at 4:49






    • 52





      This is however the only thing on this page that got git to pull submodules the first time I checked out a repo

      – theheadofabroom
      Jan 11 '13 at 15:34






    • 2





      Can also use: git submodule update --init --recursive (particularly if the submodule in question is RestKit from a fresh clone)

      – HCdev
      Sep 30 '13 at 4:28



















    33














    Edit:



    In the comments was pointed out (by philfreo ) that the latest version is required. If there is any nested submodules that need to be in their latest version :



    git submodule foreach --recursive git pull


    -----Outdated comment below-----



    Isn't this the official way to do it ?



    git submodule update --init


    I use it every time. No problems so far.



    Edit:



    I just found that you can use:



    git submodule foreach --recursive git submodule update --init 


    Which will also recursively pull all of the submodules, i.e. dependancies.






    share|improve this answer






















    • 5





      Your answer doesn't answer the OP's question, but to do what you've proposed you can just say git submodule update --init --recursive

      – philfreo
      Apr 11 '11 at 19:30







    • 2





      I see, latest version is needed. Well this might be usefull if there is nested submodules: git submodule foreach --recursive git pull

      – antitoxic
      Apr 12 '11 at 11:14







    • 1





      I couldn't make any of these actually download anything -- "git submodule update --init --recursive" worked for me however.

      – BrainSlugs83
      Aug 28 '13 at 6:18


















    31














    As it may happens that the default branch of your submodules is not master, this is how I automate the full Git submodules upgrades:



    git submodule init
    git submodule update
    git submodule foreach 'git fetch origin; git checkout $(git rev-parse --abbrev-ref HEAD); git reset --hard origin/$(git rev-parse --abbrev-ref HEAD); git submodule update --recursive; git clean -dfx'





    share|improve this answer
































      25














      First time



      Clone and Init Submodule



      git clone git@github.com:speedovation/kiwi-resources.git resources
      git submodule init


      Rest



      During development just pull and update submodule



      git pull --recurse-submodules && git submodule update --recursive


      Update Git submodule to latest commit on origin



      git submodule foreach git pull origin master


      Preferred way should be below



      git submodule update --remote --merge


      note: last two commands have same behaviour






      share|improve this answer



























      • I did a git clone with no submodules by mistake and all other options didn't worked, no one did clone submodules. Using yours, git submodule update did the trick. Now I'm downloading submodules data missing from the clone first step. Thank you. I'm not good at git :C

        – erm3nda
        Jan 21 '16 at 11:23











      • This anser is actually a very good answer to ask a question here on top: why do I have to ".. --recursive-submodules.." and then additionally the "... update ..." and even "...foreach..." later to get latest commit? All this does not look GIT like at all! What is "update" doing and why do I have to manually go to each module to pull? Isn't that what "... --recurse-submodules .." is doing? Any hints?

        – Peter Branforn
        Jun 7 '16 at 6:53



















      18














      I don't know since which version of git this is working, but that's what you're searching for:



      git submodule update --recursive


      I use it with git pull to update the root repository, too:



      git pull && git submodule update --recursive





      share|improve this answer
































        6














        Look at http://lists.zerezo.com/git/msg674976.html which introduces a --track parameter






        share|improve this answer




















        • 2





          This is not implemented in git 1.7.1 at all at the moment.

          – vdboor
          Jul 28 '10 at 15:11











        • that will definitely be useful, if accepted eventually.

          – inger
          Dec 15 '10 at 0:08


















        5














        The above answers are good, however we were using git-hooks to make this easier but it turns out that in git 2.14, you can set git config submodule.recurse to true to enable submodules to to updated when you pull to your git repository.



        This will have the side effect of pushing all submodules change you have if they are on branches however, but if you have need of that behaviour already this could do the job.



        Can be done by using:



        git config submodule.recurse true





        share|improve this answer


































          4














          Git for windows 2.6.3:



          git submodule update --rebase --remote






          share|improve this answer

























          • That's the only one that worked for me. I wasn't even able to init or update as the submodule pointer was pointing to a version that wasn't in the remote anymore

            – Pavel
            Jul 1 '18 at 0:32


















          3














          I did this by adapting gahooa's answer above:



          Integrate it with a git [alias] ...



          If your parent project has something like this in .gitmodules:



          [submodule "opt/submodules/solarized"]
          path = opt/submodules/solarized
          url = git@github.com:altercation/solarized.git
          [submodule "opt/submodules/intellij-colors-solarized"]
          path = opt/submodules/intellij-colors-solarized
          url = git@github.com:jkaving/intellij-colors-solarized.git


          Add something like this inside your .gitconfig



          [alias]
          updatesubs = "!sh -c "git submodule init && git submodule update && git submodule status" "


          Then to update your submodules, run:



          git updatesubs


          I have an example of it in my environment setup repo.






          share|improve this answer


































            2














            Here is the command-line to pull from all of your git repositories whether they're or not submodules:



            ROOT=$(git rev-parse --show-toplevel 2> /dev/null)
            find "$ROOT" -name .git -type d -execdir git pull -v ';'


            If you running it in your top git repository, you can replace "$ROOT" into ..






            share|improve this answer


































              2














              All you need to do now is a simple git checkout



              Just make sure to enable it via this global config: git config --global submodule.recurse true






              share|improve this answer
































                2














                From the top level in the repo:



                git submodule foreach git checkout develop
                git submodule foreach git pull


                This will switch all branches to develop and pull latest






                share|improve this answer






















                • 2





                  Does not work for me, with git 2.7.

                  – Bruno Haible
                  Mar 20 at 21:27











                • Do you have something like an Everything sln file which adds all the project references in the tree? Also what error do you see? Can you check your gitignore file too

                  – Srayan Guhathakurta
                  Mar 21 at 23:13


















                1














                I think you'll have to write a script to do this. To be honest, I might install python to do it so that you can use os.walk to cd to each directory and issue the appropriate commands. Using python or some other scripting language, other than batch, would allow you to easily add/remove subprojects with out having to modify the script.






                share|improve this answer
































                  1














                  Remark: not too easy way, but workable and it has its own unique pros.



                  If one want to clone only HEAD revision of a repository and only HEADs of all the its submodules (i.e. to checkout "trunk"), then one can use following Lua script. Sometimes simple command git submodule update --init --recursive --remote --no-fetch --depth=1 can result in an unrecoverable git error. In this case one need to clean up subdirectory of .git/modules directory and clone submodule manually using git clone --separate-git-dir command. The only complexity is to find out URL, path of .git directory of submodule and path of submodule in superproject tree.



                  Remark: the script is only tested against https://github.com/boostorg/boost.git repository. Its peculiarities: all the submodules hosted on the same host and .gitmodules contains only relative URLs.



                  -- mkdir boost ; cd boost ; lua ../git-submodules-clone-HEAD.lua https://github.com/boostorg/boost.git .
                  local module_url = arg[1] or 'https://github.com/boostorg/boost.git'
                  local module = arg[2] or module_url:match('.+/([_%d%a]+)%.git')
                  local branch = arg[3] or 'master'
                  function execute(command)
                  print('# ' .. command)
                  return os.execute(command)
                  end
                  -- execute('rm -rf ' .. module)
                  if not execute('git clone --single-branch --branch master --depth=1 ' .. module_url .. ' ' .. module) then
                  io.stderr:write('can't clone repository from ' .. module_url .. ' to ' .. module .. 'n')
                  return 1
                  end
                  -- cd $module ; git submodule update --init --recursive --remote --no-fetch --depth=1
                  execute('mkdir -p ' .. module .. '/.git/modules')
                  assert(io.input(module .. '/.gitmodules'))
                  local lines =
                  for line in io.lines() do
                  table.insert(lines, line)
                  end
                  local submodule
                  local path
                  local submodule_url
                  for _, line in ipairs(lines) do
                  local submodule_ = line:match('^%[submodule %"([_%d%a]-)%"%]$')
                  if submodule_ then
                  submodule = submodule_
                  path = nil
                  submodule_url = nil
                  else
                  local path_ = line:match('^%s*path = (.+)$')
                  if path_ then
                  path = path_
                  else
                  submodule_url = line:match('^%s*url = (.+)$')
                  end
                  if submodule and path and submodule_url then
                  -- execute('rm -rf ' .. path)
                  local git_dir = module .. '/.git/modules/' .. path:match('^.-/(.+)$')
                  -- execute('rm -rf ' .. git_dir)
                  execute('mkdir -p $(dirname "' .. git_dir .. '")')
                  if not execute('git clone --depth=1 --single-branch --branch=' .. branch .. ' --separate-git-dir ' .. git_dir .. ' ' .. module_url .. '/' .. submodule_url .. ' ' .. module .. '/' .. path) then
                  io.stderr:write('can't clone submodule ' .. submodule .. 'n')
                  return 1
                  end
                  path = nil
                  submodule_url = nil
                  end
                  end
                  end





                  share|improve this answer

























                    protected by Baba Jul 23 '13 at 9:17



                    Thank you for your interest in this question.
                    Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                    Would you like to answer one of these unanswered questions instead?














                    19 Answers
                    19






                    active

                    oldest

                    votes








                    19 Answers
                    19






                    active

                    oldest

                    votes









                    active

                    oldest

                    votes






                    active

                    oldest

                    votes









                    2184














                    If it's the first time you checkout 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


                    or:



                    git pull --recurse-submodules


                    if you want to pull your submodules to latest commits intead of what the repo points to.



                    See git-submodule(1) for details






                    share|improve this answer






















                    • 285





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

                      – Jens Kohl
                      Sep 30 '11 at 14:12






                    • 34





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

                      – Bogdan Gusiev
                      Nov 7 '11 at 13:27







                    • 15





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

                      – Peter DeWeese
                      Dec 18 '12 at 20:56






                    • 21





                      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.

                      – Nathan Hornby
                      Jul 23 '14 at 18:00







                    • 25





                      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 '15 at 16:14
















                    2184














                    If it's the first time you checkout 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


                    or:



                    git pull --recurse-submodules


                    if you want to pull your submodules to latest commits intead of what the repo points to.



                    See git-submodule(1) for details






                    share|improve this answer






















                    • 285





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

                      – Jens Kohl
                      Sep 30 '11 at 14:12






                    • 34





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

                      – Bogdan Gusiev
                      Nov 7 '11 at 13:27







                    • 15





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

                      – Peter DeWeese
                      Dec 18 '12 at 20:56






                    • 21





                      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.

                      – Nathan Hornby
                      Jul 23 '14 at 18:00







                    • 25





                      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 '15 at 16:14














                    2184












                    2184








                    2184







                    If it's the first time you checkout 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


                    or:



                    git pull --recurse-submodules


                    if you want to pull your submodules to latest commits intead of what the repo points to.



                    See git-submodule(1) for details






                    share|improve this answer















                    If it's the first time you checkout 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


                    or:



                    git pull --recurse-submodules


                    if you want to pull your submodules to latest commits intead of what the repo points to.



                    See git-submodule(1) for details







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited May 28 at 14:56

























                    answered Jun 23 '09 at 13:42









                    Henrik GustafssonHenrik Gustafsson

                    35.1k7 gold badges40 silver badges59 bronze badges




                    35.1k7 gold badges40 silver badges59 bronze badges










                    • 285





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

                      – Jens Kohl
                      Sep 30 '11 at 14:12






                    • 34





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

                      – Bogdan Gusiev
                      Nov 7 '11 at 13:27







                    • 15





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

                      – Peter DeWeese
                      Dec 18 '12 at 20:56






                    • 21





                      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.

                      – Nathan Hornby
                      Jul 23 '14 at 18:00







                    • 25





                      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 '15 at 16:14













                    • 285





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

                      – Jens Kohl
                      Sep 30 '11 at 14:12






                    • 34





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

                      – Bogdan Gusiev
                      Nov 7 '11 at 13:27







                    • 15





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

                      – Peter DeWeese
                      Dec 18 '12 at 20:56






                    • 21





                      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.

                      – Nathan Hornby
                      Jul 23 '14 at 18:00







                    • 25





                      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 '15 at 16:14








                    285




                    285





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

                    – Jens Kohl
                    Sep 30 '11 at 14:12





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

                    – Jens Kohl
                    Sep 30 '11 at 14:12




                    34




                    34





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

                    – Bogdan Gusiev
                    Nov 7 '11 at 13:27






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

                    – Bogdan Gusiev
                    Nov 7 '11 at 13:27





                    15




                    15





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

                    – Peter DeWeese
                    Dec 18 '12 at 20:56





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

                    – Peter DeWeese
                    Dec 18 '12 at 20:56




                    21




                    21





                    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.

                    – Nathan Hornby
                    Jul 23 '14 at 18:00






                    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.

                    – Nathan Hornby
                    Jul 23 '14 at 18:00





                    25




                    25





                    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 '15 at 16:14






                    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 '15 at 16:14














                    601














                    If you need to pull stuff for submodules into your submodule repositories use



                    git pull --recurse-submodules



                    a feature git first learned in 1.7.3.




                    But this will not checkout proper commits(the ones your master repository points to) in submodules



                    To checkout proper commits in your submodules you should update them after pulling using



                    git submodule update --recursive --remote





                    share|improve this answer






















                    • 29





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

                      – Stephen C
                      Dec 6 '11 at 22:41







                    • 3





                      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.

                      – Matt Browne
                      Jan 24 '13 at 4:11






                    • 7





                      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.

                      – Chris Moschini
                      Jun 12 '14 at 17:09






                    • 11





                      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.

                      – patryk.beza
                      Mar 2 '16 at 22:59







                    • 1





                      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 '16 at 10:59















                    601














                    If you need to pull stuff for submodules into your submodule repositories use



                    git pull --recurse-submodules



                    a feature git first learned in 1.7.3.




                    But this will not checkout proper commits(the ones your master repository points to) in submodules



                    To checkout proper commits in your submodules you should update them after pulling using



                    git submodule update --recursive --remote





                    share|improve this answer






















                    • 29





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

                      – Stephen C
                      Dec 6 '11 at 22:41







                    • 3





                      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.

                      – Matt Browne
                      Jan 24 '13 at 4:11






                    • 7





                      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.

                      – Chris Moschini
                      Jun 12 '14 at 17:09






                    • 11





                      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.

                      – patryk.beza
                      Mar 2 '16 at 22:59







                    • 1





                      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 '16 at 10:59













                    601












                    601








                    601







                    If you need to pull stuff for submodules into your submodule repositories use



                    git pull --recurse-submodules



                    a feature git first learned in 1.7.3.




                    But this will not checkout proper commits(the ones your master repository points to) in submodules



                    To checkout proper commits in your submodules you should update them after pulling using



                    git submodule update --recursive --remote





                    share|improve this answer















                    If you need to pull stuff for submodules into your submodule repositories use



                    git pull --recurse-submodules



                    a feature git first learned in 1.7.3.




                    But this will not checkout proper commits(the ones your master repository points to) in submodules



                    To checkout proper commits in your submodules you should update them after pulling using



                    git submodule update --recursive --remote






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Oct 27 '16 at 14:02

























                    answered Nov 10 '11 at 18:07









                    Alexander BartoshAlexander Bartosh

                    6,6461 gold badge13 silver badges18 bronze badges




                    6,6461 gold badge13 silver badges18 bronze badges










                    • 29





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

                      – Stephen C
                      Dec 6 '11 at 22:41







                    • 3





                      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.

                      – Matt Browne
                      Jan 24 '13 at 4:11






                    • 7





                      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.

                      – Chris Moschini
                      Jun 12 '14 at 17:09






                    • 11





                      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.

                      – patryk.beza
                      Mar 2 '16 at 22:59







                    • 1





                      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 '16 at 10:59












                    • 29





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

                      – Stephen C
                      Dec 6 '11 at 22:41







                    • 3





                      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.

                      – Matt Browne
                      Jan 24 '13 at 4:11






                    • 7





                      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.

                      – Chris Moschini
                      Jun 12 '14 at 17:09






                    • 11





                      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.

                      – patryk.beza
                      Mar 2 '16 at 22:59







                    • 1





                      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 '16 at 10:59







                    29




                    29





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

                    – Stephen C
                    Dec 6 '11 at 22:41






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

                    – Stephen C
                    Dec 6 '11 at 22:41





                    3




                    3





                    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.

                    – Matt Browne
                    Jan 24 '13 at 4:11





                    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.

                    – Matt Browne
                    Jan 24 '13 at 4:11




                    7




                    7





                    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.

                    – Chris Moschini
                    Jun 12 '14 at 17:09





                    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.

                    – Chris Moschini
                    Jun 12 '14 at 17:09




                    11




                    11





                    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.

                    – patryk.beza
                    Mar 2 '16 at 22:59






                    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.

                    – patryk.beza
                    Mar 2 '16 at 22:59





                    1




                    1





                    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 '16 at 10:59





                    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 '16 at 10:59











                    369














                    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.



                    Explained



                    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.






                    share|improve this answer






















                    • 10





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

                      – Michael Scott Cuthbert
                      Aug 28 '15 at 17:52






                    • 2





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

                      – abc123
                      Aug 28 '15 at 19:28






                    • 3





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

                      – Nathan Osman
                      Apr 5 '16 at 4:44







                    • 3





                      @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 '16 at 19:39






                    • 2





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

                      – Nathan Osman
                      Apr 6 '16 at 23:31















                    369














                    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.



                    Explained



                    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.






                    share|improve this answer






















                    • 10





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

                      – Michael Scott Cuthbert
                      Aug 28 '15 at 17:52






                    • 2





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

                      – abc123
                      Aug 28 '15 at 19:28






                    • 3





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

                      – Nathan Osman
                      Apr 5 '16 at 4:44







                    • 3





                      @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 '16 at 19:39






                    • 2





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

                      – Nathan Osman
                      Apr 6 '16 at 23:31













                    369












                    369








                    369







                    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.



                    Explained



                    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.






                    share|improve this answer















                    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.



                    Explained



                    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.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Jul 12 at 17:59

























                    answered Dec 11 '14 at 19:38









                    abc123abc123

                    14.1k5 gold badges40 silver badges71 bronze badges




                    14.1k5 gold badges40 silver badges71 bronze badges










                    • 10





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

                      – Michael Scott Cuthbert
                      Aug 28 '15 at 17:52






                    • 2





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

                      – abc123
                      Aug 28 '15 at 19:28






                    • 3





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

                      – Nathan Osman
                      Apr 5 '16 at 4:44







                    • 3





                      @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 '16 at 19:39






                    • 2





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

                      – Nathan Osman
                      Apr 6 '16 at 23:31












                    • 10





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

                      – Michael Scott Cuthbert
                      Aug 28 '15 at 17:52






                    • 2





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

                      – abc123
                      Aug 28 '15 at 19:28






                    • 3





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

                      – Nathan Osman
                      Apr 5 '16 at 4:44







                    • 3





                      @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 '16 at 19:39






                    • 2





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

                      – Nathan Osman
                      Apr 6 '16 at 23:31







                    10




                    10





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

                    – Michael Scott Cuthbert
                    Aug 28 '15 at 17:52





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

                    – Michael Scott Cuthbert
                    Aug 28 '15 at 17:52




                    2




                    2





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

                    – abc123
                    Aug 28 '15 at 19:28





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

                    – abc123
                    Aug 28 '15 at 19:28




                    3




                    3





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

                    – Nathan Osman
                    Apr 5 '16 at 4:44






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

                    – Nathan Osman
                    Apr 5 '16 at 4:44





                    3




                    3





                    @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 '16 at 19:39





                    @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 '16 at 19:39




                    2




                    2





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

                    – Nathan Osman
                    Apr 6 '16 at 23:31





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

                    – Nathan Osman
                    Apr 6 '16 at 23:31











                    302














                    Note: This is from 2009 and may have been good then but there are better options now.



                    We use this. It's called git-pup:



                    #!/bin/bash
                    # Exists to fully update the git repo that you are sitting in...

                    git pull && git submodule init && git submodule update && git submodule status


                    Just put it in a suitable bin directory (/usr/local/bin). If on Windows, you may need to modify the syntax to get it to work :)



                    Update:



                    In response to the comment by the original author about pulling in all of the HEADs of all of the submodules -- that is a good question.



                    I am pretty sure that git does not have a command for this internally. In order to do so, you would need to identify what HEAD really is for a submodule. That could be as simple as saying master is the most up to date branch, etc...



                    Following this, create a simple script that does the following:



                    1. check git submodule status for "modified" repositories. The first character of the output lines indicates this. If a sub-repo is modified, you may NOT want to proceed.

                    2. for each repo listed, cd into it's directory and run git checkout master && git pull. Check for errors.

                    3. At the end, I suggest you print a display to the user to indicate the current status of the submodules -- perhaps prompt them to add all and commit?

                    I'd like to mention that this style is not really what git submodules were designed for. Typically, you want to say "LibraryX" is at version "2.32" and will stay that way until I tell it to "upgrade".



                    That is, in a sense, what you are doing with the described script, but just more automatically. Care is required!



                    Update 2:



                    If you are on a windows platform, you may want to look at using Python to implement the script as it is very capable in these areas. If you are on unix/linux, then I suggest just a bash script.



                    Need any clarifications? Just post a comment.






                    share|improve this answer



























                    • I don't think that's what I want. Won't that pull the version of the submodules that the super-project was last committed with. I want to pull the head version of all the submodules.

                      – Brad Robinson
                      Jun 23 '09 at 2:30






                    • 3





                      This works great, and works not only to update the submodules but also to fetch them for the first time if that's what you need.

                      – Matt Browne
                      Jan 24 '13 at 4:12











                    • I'm just getting "There is no tracking information for the current branch. Please specify which branch you want to merge with." No matter what I try :/

                      – Nathan Hornby
                      Aug 4 '14 at 9:45






                    • 7





                      Why not create an alias for it? git config --global alias.pup '!git pull && git submodule init && git submodule update && git submodule status' and then use it as git pup without any scripting.

                      – fracz
                      Feb 11 '16 at 21:40











                    • Thank you, for some reason even though I have git 1.9.1 I had to perform git submodule init after first pull that had submodules included, so that everything would start working properly.

                      – Ben Usman
                      May 12 '16 at 21:25















                    302














                    Note: This is from 2009 and may have been good then but there are better options now.



                    We use this. It's called git-pup:



                    #!/bin/bash
                    # Exists to fully update the git repo that you are sitting in...

                    git pull && git submodule init && git submodule update && git submodule status


                    Just put it in a suitable bin directory (/usr/local/bin). If on Windows, you may need to modify the syntax to get it to work :)



                    Update:



                    In response to the comment by the original author about pulling in all of the HEADs of all of the submodules -- that is a good question.



                    I am pretty sure that git does not have a command for this internally. In order to do so, you would need to identify what HEAD really is for a submodule. That could be as simple as saying master is the most up to date branch, etc...



                    Following this, create a simple script that does the following:



                    1. check git submodule status for "modified" repositories. The first character of the output lines indicates this. If a sub-repo is modified, you may NOT want to proceed.

                    2. for each repo listed, cd into it's directory and run git checkout master && git pull. Check for errors.

                    3. At the end, I suggest you print a display to the user to indicate the current status of the submodules -- perhaps prompt them to add all and commit?

                    I'd like to mention that this style is not really what git submodules were designed for. Typically, you want to say "LibraryX" is at version "2.32" and will stay that way until I tell it to "upgrade".



                    That is, in a sense, what you are doing with the described script, but just more automatically. Care is required!



                    Update 2:



                    If you are on a windows platform, you may want to look at using Python to implement the script as it is very capable in these areas. If you are on unix/linux, then I suggest just a bash script.



                    Need any clarifications? Just post a comment.






                    share|improve this answer



























                    • I don't think that's what I want. Won't that pull the version of the submodules that the super-project was last committed with. I want to pull the head version of all the submodules.

                      – Brad Robinson
                      Jun 23 '09 at 2:30






                    • 3





                      This works great, and works not only to update the submodules but also to fetch them for the first time if that's what you need.

                      – Matt Browne
                      Jan 24 '13 at 4:12











                    • I'm just getting "There is no tracking information for the current branch. Please specify which branch you want to merge with." No matter what I try :/

                      – Nathan Hornby
                      Aug 4 '14 at 9:45






                    • 7





                      Why not create an alias for it? git config --global alias.pup '!git pull && git submodule init && git submodule update && git submodule status' and then use it as git pup without any scripting.

                      – fracz
                      Feb 11 '16 at 21:40











                    • Thank you, for some reason even though I have git 1.9.1 I had to perform git submodule init after first pull that had submodules included, so that everything would start working properly.

                      – Ben Usman
                      May 12 '16 at 21:25













                    302












                    302








                    302







                    Note: This is from 2009 and may have been good then but there are better options now.



                    We use this. It's called git-pup:



                    #!/bin/bash
                    # Exists to fully update the git repo that you are sitting in...

                    git pull && git submodule init && git submodule update && git submodule status


                    Just put it in a suitable bin directory (/usr/local/bin). If on Windows, you may need to modify the syntax to get it to work :)



                    Update:



                    In response to the comment by the original author about pulling in all of the HEADs of all of the submodules -- that is a good question.



                    I am pretty sure that git does not have a command for this internally. In order to do so, you would need to identify what HEAD really is for a submodule. That could be as simple as saying master is the most up to date branch, etc...



                    Following this, create a simple script that does the following:



                    1. check git submodule status for "modified" repositories. The first character of the output lines indicates this. If a sub-repo is modified, you may NOT want to proceed.

                    2. for each repo listed, cd into it's directory and run git checkout master && git pull. Check for errors.

                    3. At the end, I suggest you print a display to the user to indicate the current status of the submodules -- perhaps prompt them to add all and commit?

                    I'd like to mention that this style is not really what git submodules were designed for. Typically, you want to say "LibraryX" is at version "2.32" and will stay that way until I tell it to "upgrade".



                    That is, in a sense, what you are doing with the described script, but just more automatically. Care is required!



                    Update 2:



                    If you are on a windows platform, you may want to look at using Python to implement the script as it is very capable in these areas. If you are on unix/linux, then I suggest just a bash script.



                    Need any clarifications? Just post a comment.






                    share|improve this answer















                    Note: This is from 2009 and may have been good then but there are better options now.



                    We use this. It's called git-pup:



                    #!/bin/bash
                    # Exists to fully update the git repo that you are sitting in...

                    git pull && git submodule init && git submodule update && git submodule status


                    Just put it in a suitable bin directory (/usr/local/bin). If on Windows, you may need to modify the syntax to get it to work :)



                    Update:



                    In response to the comment by the original author about pulling in all of the HEADs of all of the submodules -- that is a good question.



                    I am pretty sure that git does not have a command for this internally. In order to do so, you would need to identify what HEAD really is for a submodule. That could be as simple as saying master is the most up to date branch, etc...



                    Following this, create a simple script that does the following:



                    1. check git submodule status for "modified" repositories. The first character of the output lines indicates this. If a sub-repo is modified, you may NOT want to proceed.

                    2. for each repo listed, cd into it's directory and run git checkout master && git pull. Check for errors.

                    3. At the end, I suggest you print a display to the user to indicate the current status of the submodules -- perhaps prompt them to add all and commit?

                    I'd like to mention that this style is not really what git submodules were designed for. Typically, you want to say "LibraryX" is at version "2.32" and will stay that way until I tell it to "upgrade".



                    That is, in a sense, what you are doing with the described script, but just more automatically. Care is required!



                    Update 2:



                    If you are on a windows platform, you may want to look at using Python to implement the script as it is very capable in these areas. If you are on unix/linux, then I suggest just a bash script.



                    Need any clarifications? Just post a comment.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Feb 20 '17 at 19:37

























                    answered Jun 23 '09 at 1:50









                    gahooagahooa

                    95.3k12 gold badges83 silver badges90 bronze badges




                    95.3k12 gold badges83 silver badges90 bronze badges















                    • I don't think that's what I want. Won't that pull the version of the submodules that the super-project was last committed with. I want to pull the head version of all the submodules.

                      – Brad Robinson
                      Jun 23 '09 at 2:30






                    • 3





                      This works great, and works not only to update the submodules but also to fetch them for the first time if that's what you need.

                      – Matt Browne
                      Jan 24 '13 at 4:12











                    • I'm just getting "There is no tracking information for the current branch. Please specify which branch you want to merge with." No matter what I try :/

                      – Nathan Hornby
                      Aug 4 '14 at 9:45






                    • 7





                      Why not create an alias for it? git config --global alias.pup '!git pull && git submodule init && git submodule update && git submodule status' and then use it as git pup without any scripting.

                      – fracz
                      Feb 11 '16 at 21:40











                    • Thank you, for some reason even though I have git 1.9.1 I had to perform git submodule init after first pull that had submodules included, so that everything would start working properly.

                      – Ben Usman
                      May 12 '16 at 21:25

















                    • I don't think that's what I want. Won't that pull the version of the submodules that the super-project was last committed with. I want to pull the head version of all the submodules.

                      – Brad Robinson
                      Jun 23 '09 at 2:30






                    • 3





                      This works great, and works not only to update the submodules but also to fetch them for the first time if that's what you need.

                      – Matt Browne
                      Jan 24 '13 at 4:12











                    • I'm just getting "There is no tracking information for the current branch. Please specify which branch you want to merge with." No matter what I try :/

                      – Nathan Hornby
                      Aug 4 '14 at 9:45






                    • 7





                      Why not create an alias for it? git config --global alias.pup '!git pull && git submodule init && git submodule update && git submodule status' and then use it as git pup without any scripting.

                      – fracz
                      Feb 11 '16 at 21:40











                    • Thank you, for some reason even though I have git 1.9.1 I had to perform git submodule init after first pull that had submodules included, so that everything would start working properly.

                      – Ben Usman
                      May 12 '16 at 21:25
















                    I don't think that's what I want. Won't that pull the version of the submodules that the super-project was last committed with. I want to pull the head version of all the submodules.

                    – Brad Robinson
                    Jun 23 '09 at 2:30





                    I don't think that's what I want. Won't that pull the version of the submodules that the super-project was last committed with. I want to pull the head version of all the submodules.

                    – Brad Robinson
                    Jun 23 '09 at 2:30




                    3




                    3





                    This works great, and works not only to update the submodules but also to fetch them for the first time if that's what you need.

                    – Matt Browne
                    Jan 24 '13 at 4:12





                    This works great, and works not only to update the submodules but also to fetch them for the first time if that's what you need.

                    – Matt Browne
                    Jan 24 '13 at 4:12













                    I'm just getting "There is no tracking information for the current branch. Please specify which branch you want to merge with." No matter what I try :/

                    – Nathan Hornby
                    Aug 4 '14 at 9:45





                    I'm just getting "There is no tracking information for the current branch. Please specify which branch you want to merge with." No matter what I try :/

                    – Nathan Hornby
                    Aug 4 '14 at 9:45




                    7




                    7





                    Why not create an alias for it? git config --global alias.pup '!git pull && git submodule init && git submodule update && git submodule status' and then use it as git pup without any scripting.

                    – fracz
                    Feb 11 '16 at 21:40





                    Why not create an alias for it? git config --global alias.pup '!git pull && git submodule init && git submodule update && git submodule status' and then use it as git pup without any scripting.

                    – fracz
                    Feb 11 '16 at 21:40













                    Thank you, for some reason even though I have git 1.9.1 I had to perform git submodule init after first pull that had submodules included, so that everything would start working properly.

                    – Ben Usman
                    May 12 '16 at 21:25





                    Thank you, for some reason even though I have git 1.9.1 I had to perform git submodule init after first pull that had submodules included, so that everything would start working properly.

                    – Ben Usman
                    May 12 '16 at 21:25











                    154














                    Henrik is on the right track. The 'foreach' command can execute any arbitrary shell script. Two options to pull the very latest might be,



                    git submodule foreach git pull origin master


                    and,



                    git submodule foreach /path/to/some/cool/script.sh


                    That will iterate through all initialized submodules and run the given commands.






                    share|improve this answer





























                      154














                      Henrik is on the right track. The 'foreach' command can execute any arbitrary shell script. Two options to pull the very latest might be,



                      git submodule foreach git pull origin master


                      and,



                      git submodule foreach /path/to/some/cool/script.sh


                      That will iterate through all initialized submodules and run the given commands.






                      share|improve this answer



























                        154












                        154








                        154







                        Henrik is on the right track. The 'foreach' command can execute any arbitrary shell script. Two options to pull the very latest might be,



                        git submodule foreach git pull origin master


                        and,



                        git submodule foreach /path/to/some/cool/script.sh


                        That will iterate through all initialized submodules and run the given commands.






                        share|improve this answer













                        Henrik is on the right track. The 'foreach' command can execute any arbitrary shell script. Two options to pull the very latest might be,



                        git submodule foreach git pull origin master


                        and,



                        git submodule foreach /path/to/some/cool/script.sh


                        That will iterate through all initialized submodules and run the given commands.







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Jun 23 '09 at 14:21









                        mturquettemturquette

                        1,6171 gold badge9 silver badges3 bronze badges




                        1,6171 gold badge9 silver badges3 bronze badges
























                            143














                            The following worked for me on Windows.



                            git submodule init
                            git submodule update





                            share|improve this answer




















                            • 5





                              This clearly is not what the OP asked for. It will only update to the associated submodule commit and not the latest one.

                              – Patrick
                              Oct 29 '11 at 4:49






                            • 52





                              This is however the only thing on this page that got git to pull submodules the first time I checked out a repo

                              – theheadofabroom
                              Jan 11 '13 at 15:34






                            • 2





                              Can also use: git submodule update --init --recursive (particularly if the submodule in question is RestKit from a fresh clone)

                              – HCdev
                              Sep 30 '13 at 4:28
















                            143














                            The following worked for me on Windows.



                            git submodule init
                            git submodule update





                            share|improve this answer




















                            • 5





                              This clearly is not what the OP asked for. It will only update to the associated submodule commit and not the latest one.

                              – Patrick
                              Oct 29 '11 at 4:49






                            • 52





                              This is however the only thing on this page that got git to pull submodules the first time I checked out a repo

                              – theheadofabroom
                              Jan 11 '13 at 15:34






                            • 2





                              Can also use: git submodule update --init --recursive (particularly if the submodule in question is RestKit from a fresh clone)

                              – HCdev
                              Sep 30 '13 at 4:28














                            143












                            143








                            143







                            The following worked for me on Windows.



                            git submodule init
                            git submodule update





                            share|improve this answer













                            The following worked for me on Windows.



                            git submodule init
                            git submodule update






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jul 22 '11 at 13:12









                            zachleatzachleat

                            3,0171 gold badge19 silver badges20 bronze badges




                            3,0171 gold badge19 silver badges20 bronze badges










                            • 5





                              This clearly is not what the OP asked for. It will only update to the associated submodule commit and not the latest one.

                              – Patrick
                              Oct 29 '11 at 4:49






                            • 52





                              This is however the only thing on this page that got git to pull submodules the first time I checked out a repo

                              – theheadofabroom
                              Jan 11 '13 at 15:34






                            • 2





                              Can also use: git submodule update --init --recursive (particularly if the submodule in question is RestKit from a fresh clone)

                              – HCdev
                              Sep 30 '13 at 4:28













                            • 5





                              This clearly is not what the OP asked for. It will only update to the associated submodule commit and not the latest one.

                              – Patrick
                              Oct 29 '11 at 4:49






                            • 52





                              This is however the only thing on this page that got git to pull submodules the first time I checked out a repo

                              – theheadofabroom
                              Jan 11 '13 at 15:34






                            • 2





                              Can also use: git submodule update --init --recursive (particularly if the submodule in question is RestKit from a fresh clone)

                              – HCdev
                              Sep 30 '13 at 4:28








                            5




                            5





                            This clearly is not what the OP asked for. It will only update to the associated submodule commit and not the latest one.

                            – Patrick
                            Oct 29 '11 at 4:49





                            This clearly is not what the OP asked for. It will only update to the associated submodule commit and not the latest one.

                            – Patrick
                            Oct 29 '11 at 4:49




                            52




                            52





                            This is however the only thing on this page that got git to pull submodules the first time I checked out a repo

                            – theheadofabroom
                            Jan 11 '13 at 15:34





                            This is however the only thing on this page that got git to pull submodules the first time I checked out a repo

                            – theheadofabroom
                            Jan 11 '13 at 15:34




                            2




                            2





                            Can also use: git submodule update --init --recursive (particularly if the submodule in question is RestKit from a fresh clone)

                            – HCdev
                            Sep 30 '13 at 4:28






                            Can also use: git submodule update --init --recursive (particularly if the submodule in question is RestKit from a fresh clone)

                            – HCdev
                            Sep 30 '13 at 4:28












                            33














                            Edit:



                            In the comments was pointed out (by philfreo ) that the latest version is required. If there is any nested submodules that need to be in their latest version :



                            git submodule foreach --recursive git pull


                            -----Outdated comment below-----



                            Isn't this the official way to do it ?



                            git submodule update --init


                            I use it every time. No problems so far.



                            Edit:



                            I just found that you can use:



                            git submodule foreach --recursive git submodule update --init 


                            Which will also recursively pull all of the submodules, i.e. dependancies.






                            share|improve this answer






















                            • 5





                              Your answer doesn't answer the OP's question, but to do what you've proposed you can just say git submodule update --init --recursive

                              – philfreo
                              Apr 11 '11 at 19:30







                            • 2





                              I see, latest version is needed. Well this might be usefull if there is nested submodules: git submodule foreach --recursive git pull

                              – antitoxic
                              Apr 12 '11 at 11:14







                            • 1





                              I couldn't make any of these actually download anything -- "git submodule update --init --recursive" worked for me however.

                              – BrainSlugs83
                              Aug 28 '13 at 6:18















                            33














                            Edit:



                            In the comments was pointed out (by philfreo ) that the latest version is required. If there is any nested submodules that need to be in their latest version :



                            git submodule foreach --recursive git pull


                            -----Outdated comment below-----



                            Isn't this the official way to do it ?



                            git submodule update --init


                            I use it every time. No problems so far.



                            Edit:



                            I just found that you can use:



                            git submodule foreach --recursive git submodule update --init 


                            Which will also recursively pull all of the submodules, i.e. dependancies.






                            share|improve this answer






















                            • 5





                              Your answer doesn't answer the OP's question, but to do what you've proposed you can just say git submodule update --init --recursive

                              – philfreo
                              Apr 11 '11 at 19:30







                            • 2





                              I see, latest version is needed. Well this might be usefull if there is nested submodules: git submodule foreach --recursive git pull

                              – antitoxic
                              Apr 12 '11 at 11:14







                            • 1





                              I couldn't make any of these actually download anything -- "git submodule update --init --recursive" worked for me however.

                              – BrainSlugs83
                              Aug 28 '13 at 6:18













                            33












                            33








                            33







                            Edit:



                            In the comments was pointed out (by philfreo ) that the latest version is required. If there is any nested submodules that need to be in their latest version :



                            git submodule foreach --recursive git pull


                            -----Outdated comment below-----



                            Isn't this the official way to do it ?



                            git submodule update --init


                            I use it every time. No problems so far.



                            Edit:



                            I just found that you can use:



                            git submodule foreach --recursive git submodule update --init 


                            Which will also recursively pull all of the submodules, i.e. dependancies.






                            share|improve this answer















                            Edit:



                            In the comments was pointed out (by philfreo ) that the latest version is required. If there is any nested submodules that need to be in their latest version :



                            git submodule foreach --recursive git pull


                            -----Outdated comment below-----



                            Isn't this the official way to do it ?



                            git submodule update --init


                            I use it every time. No problems so far.



                            Edit:



                            I just found that you can use:



                            git submodule foreach --recursive git submodule update --init 


                            Which will also recursively pull all of the submodules, i.e. dependancies.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Apr 12 '11 at 11:21

























                            answered Apr 5 '11 at 16:23









                            antitoxicantitoxic

                            3,06030 silver badges43 bronze badges




                            3,06030 silver badges43 bronze badges










                            • 5





                              Your answer doesn't answer the OP's question, but to do what you've proposed you can just say git submodule update --init --recursive

                              – philfreo
                              Apr 11 '11 at 19:30







                            • 2





                              I see, latest version is needed. Well this might be usefull if there is nested submodules: git submodule foreach --recursive git pull

                              – antitoxic
                              Apr 12 '11 at 11:14







                            • 1





                              I couldn't make any of these actually download anything -- "git submodule update --init --recursive" worked for me however.

                              – BrainSlugs83
                              Aug 28 '13 at 6:18












                            • 5





                              Your answer doesn't answer the OP's question, but to do what you've proposed you can just say git submodule update --init --recursive

                              – philfreo
                              Apr 11 '11 at 19:30







                            • 2





                              I see, latest version is needed. Well this might be usefull if there is nested submodules: git submodule foreach --recursive git pull

                              – antitoxic
                              Apr 12 '11 at 11:14







                            • 1





                              I couldn't make any of these actually download anything -- "git submodule update --init --recursive" worked for me however.

                              – BrainSlugs83
                              Aug 28 '13 at 6:18







                            5




                            5





                            Your answer doesn't answer the OP's question, but to do what you've proposed you can just say git submodule update --init --recursive

                            – philfreo
                            Apr 11 '11 at 19:30






                            Your answer doesn't answer the OP's question, but to do what you've proposed you can just say git submodule update --init --recursive

                            – philfreo
                            Apr 11 '11 at 19:30





                            2




                            2





                            I see, latest version is needed. Well this might be usefull if there is nested submodules: git submodule foreach --recursive git pull

                            – antitoxic
                            Apr 12 '11 at 11:14






                            I see, latest version is needed. Well this might be usefull if there is nested submodules: git submodule foreach --recursive git pull

                            – antitoxic
                            Apr 12 '11 at 11:14





                            1




                            1





                            I couldn't make any of these actually download anything -- "git submodule update --init --recursive" worked for me however.

                            – BrainSlugs83
                            Aug 28 '13 at 6:18





                            I couldn't make any of these actually download anything -- "git submodule update --init --recursive" worked for me however.

                            – BrainSlugs83
                            Aug 28 '13 at 6:18











                            31














                            As it may happens that the default branch of your submodules is not master, this is how I automate the full Git submodules upgrades:



                            git submodule init
                            git submodule update
                            git submodule foreach 'git fetch origin; git checkout $(git rev-parse --abbrev-ref HEAD); git reset --hard origin/$(git rev-parse --abbrev-ref HEAD); git submodule update --recursive; git clean -dfx'





                            share|improve this answer





























                              31














                              As it may happens that the default branch of your submodules is not master, this is how I automate the full Git submodules upgrades:



                              git submodule init
                              git submodule update
                              git submodule foreach 'git fetch origin; git checkout $(git rev-parse --abbrev-ref HEAD); git reset --hard origin/$(git rev-parse --abbrev-ref HEAD); git submodule update --recursive; git clean -dfx'





                              share|improve this answer



























                                31












                                31








                                31







                                As it may happens that the default branch of your submodules is not master, this is how I automate the full Git submodules upgrades:



                                git submodule init
                                git submodule update
                                git submodule foreach 'git fetch origin; git checkout $(git rev-parse --abbrev-ref HEAD); git reset --hard origin/$(git rev-parse --abbrev-ref HEAD); git submodule update --recursive; git clean -dfx'





                                share|improve this answer













                                As it may happens that the default branch of your submodules is not master, this is how I automate the full Git submodules upgrades:



                                git submodule init
                                git submodule update
                                git submodule foreach 'git fetch origin; git checkout $(git rev-parse --abbrev-ref HEAD); git reset --hard origin/$(git rev-parse --abbrev-ref HEAD); git submodule update --recursive; git clean -dfx'






                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Dec 4 '13 at 8:58









                                Sebastien VarretteSebastien Varrette

                                3,3531 gold badge19 silver badges18 bronze badges




                                3,3531 gold badge19 silver badges18 bronze badges
























                                    25














                                    First time



                                    Clone and Init Submodule



                                    git clone git@github.com:speedovation/kiwi-resources.git resources
                                    git submodule init


                                    Rest



                                    During development just pull and update submodule



                                    git pull --recurse-submodules && git submodule update --recursive


                                    Update Git submodule to latest commit on origin



                                    git submodule foreach git pull origin master


                                    Preferred way should be below



                                    git submodule update --remote --merge


                                    note: last two commands have same behaviour






                                    share|improve this answer



























                                    • I did a git clone with no submodules by mistake and all other options didn't worked, no one did clone submodules. Using yours, git submodule update did the trick. Now I'm downloading submodules data missing from the clone first step. Thank you. I'm not good at git :C

                                      – erm3nda
                                      Jan 21 '16 at 11:23











                                    • This anser is actually a very good answer to ask a question here on top: why do I have to ".. --recursive-submodules.." and then additionally the "... update ..." and even "...foreach..." later to get latest commit? All this does not look GIT like at all! What is "update" doing and why do I have to manually go to each module to pull? Isn't that what "... --recurse-submodules .." is doing? Any hints?

                                      – Peter Branforn
                                      Jun 7 '16 at 6:53
















                                    25














                                    First time



                                    Clone and Init Submodule



                                    git clone git@github.com:speedovation/kiwi-resources.git resources
                                    git submodule init


                                    Rest



                                    During development just pull and update submodule



                                    git pull --recurse-submodules && git submodule update --recursive


                                    Update Git submodule to latest commit on origin



                                    git submodule foreach git pull origin master


                                    Preferred way should be below



                                    git submodule update --remote --merge


                                    note: last two commands have same behaviour






                                    share|improve this answer



























                                    • I did a git clone with no submodules by mistake and all other options didn't worked, no one did clone submodules. Using yours, git submodule update did the trick. Now I'm downloading submodules data missing from the clone first step. Thank you. I'm not good at git :C

                                      – erm3nda
                                      Jan 21 '16 at 11:23











                                    • This anser is actually a very good answer to ask a question here on top: why do I have to ".. --recursive-submodules.." and then additionally the "... update ..." and even "...foreach..." later to get latest commit? All this does not look GIT like at all! What is "update" doing and why do I have to manually go to each module to pull? Isn't that what "... --recurse-submodules .." is doing? Any hints?

                                      – Peter Branforn
                                      Jun 7 '16 at 6:53














                                    25












                                    25








                                    25







                                    First time



                                    Clone and Init Submodule



                                    git clone git@github.com:speedovation/kiwi-resources.git resources
                                    git submodule init


                                    Rest



                                    During development just pull and update submodule



                                    git pull --recurse-submodules && git submodule update --recursive


                                    Update Git submodule to latest commit on origin



                                    git submodule foreach git pull origin master


                                    Preferred way should be below



                                    git submodule update --remote --merge


                                    note: last two commands have same behaviour






                                    share|improve this answer















                                    First time



                                    Clone and Init Submodule



                                    git clone git@github.com:speedovation/kiwi-resources.git resources
                                    git submodule init


                                    Rest



                                    During development just pull and update submodule



                                    git pull --recurse-submodules && git submodule update --recursive


                                    Update Git submodule to latest commit on origin



                                    git submodule foreach git pull origin master


                                    Preferred way should be below



                                    git submodule update --remote --merge


                                    note: last two commands have same behaviour







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Jan 12 '16 at 19:21

























                                    answered Sep 17 '15 at 7:18









                                    YashYash

                                    3,07925 silver badges19 bronze badges




                                    3,07925 silver badges19 bronze badges















                                    • I did a git clone with no submodules by mistake and all other options didn't worked, no one did clone submodules. Using yours, git submodule update did the trick. Now I'm downloading submodules data missing from the clone first step. Thank you. I'm not good at git :C

                                      – erm3nda
                                      Jan 21 '16 at 11:23











                                    • This anser is actually a very good answer to ask a question here on top: why do I have to ".. --recursive-submodules.." and then additionally the "... update ..." and even "...foreach..." later to get latest commit? All this does not look GIT like at all! What is "update" doing and why do I have to manually go to each module to pull? Isn't that what "... --recurse-submodules .." is doing? Any hints?

                                      – Peter Branforn
                                      Jun 7 '16 at 6:53


















                                    • I did a git clone with no submodules by mistake and all other options didn't worked, no one did clone submodules. Using yours, git submodule update did the trick. Now I'm downloading submodules data missing from the clone first step. Thank you. I'm not good at git :C

                                      – erm3nda
                                      Jan 21 '16 at 11:23











                                    • This anser is actually a very good answer to ask a question here on top: why do I have to ".. --recursive-submodules.." and then additionally the "... update ..." and even "...foreach..." later to get latest commit? All this does not look GIT like at all! What is "update" doing and why do I have to manually go to each module to pull? Isn't that what "... --recurse-submodules .." is doing? Any hints?

                                      – Peter Branforn
                                      Jun 7 '16 at 6:53

















                                    I did a git clone with no submodules by mistake and all other options didn't worked, no one did clone submodules. Using yours, git submodule update did the trick. Now I'm downloading submodules data missing from the clone first step. Thank you. I'm not good at git :C

                                    – erm3nda
                                    Jan 21 '16 at 11:23





                                    I did a git clone with no submodules by mistake and all other options didn't worked, no one did clone submodules. Using yours, git submodule update did the trick. Now I'm downloading submodules data missing from the clone first step. Thank you. I'm not good at git :C

                                    – erm3nda
                                    Jan 21 '16 at 11:23













                                    This anser is actually a very good answer to ask a question here on top: why do I have to ".. --recursive-submodules.." and then additionally the "... update ..." and even "...foreach..." later to get latest commit? All this does not look GIT like at all! What is "update" doing and why do I have to manually go to each module to pull? Isn't that what "... --recurse-submodules .." is doing? Any hints?

                                    – Peter Branforn
                                    Jun 7 '16 at 6:53






                                    This anser is actually a very good answer to ask a question here on top: why do I have to ".. --recursive-submodules.." and then additionally the "... update ..." and even "...foreach..." later to get latest commit? All this does not look GIT like at all! What is "update" doing and why do I have to manually go to each module to pull? Isn't that what "... --recurse-submodules .." is doing? Any hints?

                                    – Peter Branforn
                                    Jun 7 '16 at 6:53












                                    18














                                    I don't know since which version of git this is working, but that's what you're searching for:



                                    git submodule update --recursive


                                    I use it with git pull to update the root repository, too:



                                    git pull && git submodule update --recursive





                                    share|improve this answer





























                                      18














                                      I don't know since which version of git this is working, but that's what you're searching for:



                                      git submodule update --recursive


                                      I use it with git pull to update the root repository, too:



                                      git pull && git submodule update --recursive





                                      share|improve this answer



























                                        18












                                        18








                                        18







                                        I don't know since which version of git this is working, but that's what you're searching for:



                                        git submodule update --recursive


                                        I use it with git pull to update the root repository, too:



                                        git pull && git submodule update --recursive





                                        share|improve this answer













                                        I don't know since which version of git this is working, but that's what you're searching for:



                                        git submodule update --recursive


                                        I use it with git pull to update the root repository, too:



                                        git pull && git submodule update --recursive






                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Sep 30 '11 at 14:10









                                        Jens KohlJens Kohl

                                        3,8099 gold badges42 silver badges74 bronze badges




                                        3,8099 gold badges42 silver badges74 bronze badges
























                                            6














                                            Look at http://lists.zerezo.com/git/msg674976.html which introduces a --track parameter






                                            share|improve this answer




















                                            • 2





                                              This is not implemented in git 1.7.1 at all at the moment.

                                              – vdboor
                                              Jul 28 '10 at 15:11











                                            • that will definitely be useful, if accepted eventually.

                                              – inger
                                              Dec 15 '10 at 0:08















                                            6














                                            Look at http://lists.zerezo.com/git/msg674976.html which introduces a --track parameter






                                            share|improve this answer




















                                            • 2





                                              This is not implemented in git 1.7.1 at all at the moment.

                                              – vdboor
                                              Jul 28 '10 at 15:11











                                            • that will definitely be useful, if accepted eventually.

                                              – inger
                                              Dec 15 '10 at 0:08













                                            6












                                            6








                                            6







                                            Look at http://lists.zerezo.com/git/msg674976.html which introduces a --track parameter






                                            share|improve this answer













                                            Look at http://lists.zerezo.com/git/msg674976.html which introduces a --track parameter







                                            share|improve this answer












                                            share|improve this answer



                                            share|improve this answer










                                            answered Nov 14 '09 at 2:39









                                            jerico.devjerico.dev

                                            611 silver badge1 bronze badge




                                            611 silver badge1 bronze badge










                                            • 2





                                              This is not implemented in git 1.7.1 at all at the moment.

                                              – vdboor
                                              Jul 28 '10 at 15:11











                                            • that will definitely be useful, if accepted eventually.

                                              – inger
                                              Dec 15 '10 at 0:08












                                            • 2





                                              This is not implemented in git 1.7.1 at all at the moment.

                                              – vdboor
                                              Jul 28 '10 at 15:11











                                            • that will definitely be useful, if accepted eventually.

                                              – inger
                                              Dec 15 '10 at 0:08







                                            2




                                            2





                                            This is not implemented in git 1.7.1 at all at the moment.

                                            – vdboor
                                            Jul 28 '10 at 15:11





                                            This is not implemented in git 1.7.1 at all at the moment.

                                            – vdboor
                                            Jul 28 '10 at 15:11













                                            that will definitely be useful, if accepted eventually.

                                            – inger
                                            Dec 15 '10 at 0:08





                                            that will definitely be useful, if accepted eventually.

                                            – inger
                                            Dec 15 '10 at 0:08











                                            5














                                            The above answers are good, however we were using git-hooks to make this easier but it turns out that in git 2.14, you can set git config submodule.recurse to true to enable submodules to to updated when you pull to your git repository.



                                            This will have the side effect of pushing all submodules change you have if they are on branches however, but if you have need of that behaviour already this could do the job.



                                            Can be done by using:



                                            git config submodule.recurse true





                                            share|improve this answer































                                              5














                                              The above answers are good, however we were using git-hooks to make this easier but it turns out that in git 2.14, you can set git config submodule.recurse to true to enable submodules to to updated when you pull to your git repository.



                                              This will have the side effect of pushing all submodules change you have if they are on branches however, but if you have need of that behaviour already this could do the job.



                                              Can be done by using:



                                              git config submodule.recurse true





                                              share|improve this answer





























                                                5












                                                5








                                                5







                                                The above answers are good, however we were using git-hooks to make this easier but it turns out that in git 2.14, you can set git config submodule.recurse to true to enable submodules to to updated when you pull to your git repository.



                                                This will have the side effect of pushing all submodules change you have if they are on branches however, but if you have need of that behaviour already this could do the job.



                                                Can be done by using:



                                                git config submodule.recurse true





                                                share|improve this answer















                                                The above answers are good, however we were using git-hooks to make this easier but it turns out that in git 2.14, you can set git config submodule.recurse to true to enable submodules to to updated when you pull to your git repository.



                                                This will have the side effect of pushing all submodules change you have if they are on branches however, but if you have need of that behaviour already this could do the job.



                                                Can be done by using:



                                                git config submodule.recurse true






                                                share|improve this answer














                                                share|improve this answer



                                                share|improve this answer








                                                edited Dec 13 '18 at 17:11

























                                                answered May 22 '18 at 15:54









                                                JamesDJamesD

                                                1,51116 silver badges30 bronze badges




                                                1,51116 silver badges30 bronze badges
























                                                    4














                                                    Git for windows 2.6.3:



                                                    git submodule update --rebase --remote






                                                    share|improve this answer

























                                                    • That's the only one that worked for me. I wasn't even able to init or update as the submodule pointer was pointing to a version that wasn't in the remote anymore

                                                      – Pavel
                                                      Jul 1 '18 at 0:32















                                                    4














                                                    Git for windows 2.6.3:



                                                    git submodule update --rebase --remote






                                                    share|improve this answer

























                                                    • That's the only one that worked for me. I wasn't even able to init or update as the submodule pointer was pointing to a version that wasn't in the remote anymore

                                                      – Pavel
                                                      Jul 1 '18 at 0:32













                                                    4












                                                    4








                                                    4







                                                    Git for windows 2.6.3:



                                                    git submodule update --rebase --remote






                                                    share|improve this answer













                                                    Git for windows 2.6.3:



                                                    git submodule update --rebase --remote







                                                    share|improve this answer












                                                    share|improve this answer



                                                    share|improve this answer










                                                    answered Jan 7 '16 at 16:33









                                                    seoulseoul

                                                    7111 gold badge6 silver badges31 bronze badges




                                                    7111 gold badge6 silver badges31 bronze badges















                                                    • That's the only one that worked for me. I wasn't even able to init or update as the submodule pointer was pointing to a version that wasn't in the remote anymore

                                                      – Pavel
                                                      Jul 1 '18 at 0:32

















                                                    • That's the only one that worked for me. I wasn't even able to init or update as the submodule pointer was pointing to a version that wasn't in the remote anymore

                                                      – Pavel
                                                      Jul 1 '18 at 0:32
















                                                    That's the only one that worked for me. I wasn't even able to init or update as the submodule pointer was pointing to a version that wasn't in the remote anymore

                                                    – Pavel
                                                    Jul 1 '18 at 0:32





                                                    That's the only one that worked for me. I wasn't even able to init or update as the submodule pointer was pointing to a version that wasn't in the remote anymore

                                                    – Pavel
                                                    Jul 1 '18 at 0:32











                                                    3














                                                    I did this by adapting gahooa's answer above:



                                                    Integrate it with a git [alias] ...



                                                    If your parent project has something like this in .gitmodules:



                                                    [submodule "opt/submodules/solarized"]
                                                    path = opt/submodules/solarized
                                                    url = git@github.com:altercation/solarized.git
                                                    [submodule "opt/submodules/intellij-colors-solarized"]
                                                    path = opt/submodules/intellij-colors-solarized
                                                    url = git@github.com:jkaving/intellij-colors-solarized.git


                                                    Add something like this inside your .gitconfig



                                                    [alias]
                                                    updatesubs = "!sh -c "git submodule init && git submodule update && git submodule status" "


                                                    Then to update your submodules, run:



                                                    git updatesubs


                                                    I have an example of it in my environment setup repo.






                                                    share|improve this answer































                                                      3














                                                      I did this by adapting gahooa's answer above:



                                                      Integrate it with a git [alias] ...



                                                      If your parent project has something like this in .gitmodules:



                                                      [submodule "opt/submodules/solarized"]
                                                      path = opt/submodules/solarized
                                                      url = git@github.com:altercation/solarized.git
                                                      [submodule "opt/submodules/intellij-colors-solarized"]
                                                      path = opt/submodules/intellij-colors-solarized
                                                      url = git@github.com:jkaving/intellij-colors-solarized.git


                                                      Add something like this inside your .gitconfig



                                                      [alias]
                                                      updatesubs = "!sh -c "git submodule init && git submodule update && git submodule status" "


                                                      Then to update your submodules, run:



                                                      git updatesubs


                                                      I have an example of it in my environment setup repo.






                                                      share|improve this answer





























                                                        3












                                                        3








                                                        3







                                                        I did this by adapting gahooa's answer above:



                                                        Integrate it with a git [alias] ...



                                                        If your parent project has something like this in .gitmodules:



                                                        [submodule "opt/submodules/solarized"]
                                                        path = opt/submodules/solarized
                                                        url = git@github.com:altercation/solarized.git
                                                        [submodule "opt/submodules/intellij-colors-solarized"]
                                                        path = opt/submodules/intellij-colors-solarized
                                                        url = git@github.com:jkaving/intellij-colors-solarized.git


                                                        Add something like this inside your .gitconfig



                                                        [alias]
                                                        updatesubs = "!sh -c "git submodule init && git submodule update && git submodule status" "


                                                        Then to update your submodules, run:



                                                        git updatesubs


                                                        I have an example of it in my environment setup repo.






                                                        share|improve this answer















                                                        I did this by adapting gahooa's answer above:



                                                        Integrate it with a git [alias] ...



                                                        If your parent project has something like this in .gitmodules:



                                                        [submodule "opt/submodules/solarized"]
                                                        path = opt/submodules/solarized
                                                        url = git@github.com:altercation/solarized.git
                                                        [submodule "opt/submodules/intellij-colors-solarized"]
                                                        path = opt/submodules/intellij-colors-solarized
                                                        url = git@github.com:jkaving/intellij-colors-solarized.git


                                                        Add something like this inside your .gitconfig



                                                        [alias]
                                                        updatesubs = "!sh -c "git submodule init && git submodule update && git submodule status" "


                                                        Then to update your submodules, run:



                                                        git updatesubs


                                                        I have an example of it in my environment setup repo.







                                                        share|improve this answer














                                                        share|improve this answer



                                                        share|improve this answer








                                                        edited May 23 '17 at 10:31









                                                        Community

                                                        11 silver badge




                                                        11 silver badge










                                                        answered Jan 11 '16 at 18:59









                                                        TomTom

                                                        4495 silver badges6 bronze badges




                                                        4495 silver badges6 bronze badges
























                                                            2














                                                            Here is the command-line to pull from all of your git repositories whether they're or not submodules:



                                                            ROOT=$(git rev-parse --show-toplevel 2> /dev/null)
                                                            find "$ROOT" -name .git -type d -execdir git pull -v ';'


                                                            If you running it in your top git repository, you can replace "$ROOT" into ..






                                                            share|improve this answer































                                                              2














                                                              Here is the command-line to pull from all of your git repositories whether they're or not submodules:



                                                              ROOT=$(git rev-parse --show-toplevel 2> /dev/null)
                                                              find "$ROOT" -name .git -type d -execdir git pull -v ';'


                                                              If you running it in your top git repository, you can replace "$ROOT" into ..






                                                              share|improve this answer





























                                                                2












                                                                2








                                                                2







                                                                Here is the command-line to pull from all of your git repositories whether they're or not submodules:



                                                                ROOT=$(git rev-parse --show-toplevel 2> /dev/null)
                                                                find "$ROOT" -name .git -type d -execdir git pull -v ';'


                                                                If you running it in your top git repository, you can replace "$ROOT" into ..






                                                                share|improve this answer















                                                                Here is the command-line to pull from all of your git repositories whether they're or not submodules:



                                                                ROOT=$(git rev-parse --show-toplevel 2> /dev/null)
                                                                find "$ROOT" -name .git -type d -execdir git pull -v ';'


                                                                If you running it in your top git repository, you can replace "$ROOT" into ..







                                                                share|improve this answer














                                                                share|improve this answer



                                                                share|improve this answer








                                                                edited Sep 16 '17 at 14:07

























                                                                answered Sep 23 '15 at 9:19









                                                                kenorbkenorb

                                                                78.3k33 gold badges444 silver badges457 bronze badges




                                                                78.3k33 gold badges444 silver badges457 bronze badges
























                                                                    2














                                                                    All you need to do now is a simple git checkout



                                                                    Just make sure to enable it via this global config: git config --global submodule.recurse true






                                                                    share|improve this answer





























                                                                      2














                                                                      All you need to do now is a simple git checkout



                                                                      Just make sure to enable it via this global config: git config --global submodule.recurse true






                                                                      share|improve this answer



























                                                                        2












                                                                        2








                                                                        2







                                                                        All you need to do now is a simple git checkout



                                                                        Just make sure to enable it via this global config: git config --global submodule.recurse true






                                                                        share|improve this answer













                                                                        All you need to do now is a simple git checkout



                                                                        Just make sure to enable it via this global config: git config --global submodule.recurse true







                                                                        share|improve this answer












                                                                        share|improve this answer



                                                                        share|improve this answer










                                                                        answered Nov 22 '18 at 1:09









                                                                        PelletPellet

                                                                        1,33318 silver badges15 bronze badges




                                                                        1,33318 silver badges15 bronze badges
























                                                                            2














                                                                            From the top level in the repo:



                                                                            git submodule foreach git checkout develop
                                                                            git submodule foreach git pull


                                                                            This will switch all branches to develop and pull latest






                                                                            share|improve this answer






















                                                                            • 2





                                                                              Does not work for me, with git 2.7.

                                                                              – Bruno Haible
                                                                              Mar 20 at 21:27











                                                                            • Do you have something like an Everything sln file which adds all the project references in the tree? Also what error do you see? Can you check your gitignore file too

                                                                              – Srayan Guhathakurta
                                                                              Mar 21 at 23:13















                                                                            2














                                                                            From the top level in the repo:



                                                                            git submodule foreach git checkout develop
                                                                            git submodule foreach git pull


                                                                            This will switch all branches to develop and pull latest






                                                                            share|improve this answer






















                                                                            • 2





                                                                              Does not work for me, with git 2.7.

                                                                              – Bruno Haible
                                                                              Mar 20 at 21:27











                                                                            • Do you have something like an Everything sln file which adds all the project references in the tree? Also what error do you see? Can you check your gitignore file too

                                                                              – Srayan Guhathakurta
                                                                              Mar 21 at 23:13













                                                                            2












                                                                            2








                                                                            2







                                                                            From the top level in the repo:



                                                                            git submodule foreach git checkout develop
                                                                            git submodule foreach git pull


                                                                            This will switch all branches to develop and pull latest






                                                                            share|improve this answer















                                                                            From the top level in the repo:



                                                                            git submodule foreach git checkout develop
                                                                            git submodule foreach git pull


                                                                            This will switch all branches to develop and pull latest







                                                                            share|improve this answer














                                                                            share|improve this answer



                                                                            share|improve this answer








                                                                            edited Mar 7 at 9:43









                                                                            ljgw

                                                                            2,5411 gold badge12 silver badges36 bronze badges




                                                                            2,5411 gold badge12 silver badges36 bronze badges










                                                                            answered Feb 1 at 20:58









                                                                            Srayan GuhathakurtaSrayan Guhathakurta

                                                                            3212 silver badges9 bronze badges




                                                                            3212 silver badges9 bronze badges










                                                                            • 2





                                                                              Does not work for me, with git 2.7.

                                                                              – Bruno Haible
                                                                              Mar 20 at 21:27











                                                                            • Do you have something like an Everything sln file which adds all the project references in the tree? Also what error do you see? Can you check your gitignore file too

                                                                              – Srayan Guhathakurta
                                                                              Mar 21 at 23:13












                                                                            • 2





                                                                              Does not work for me, with git 2.7.

                                                                              – Bruno Haible
                                                                              Mar 20 at 21:27











                                                                            • Do you have something like an Everything sln file which adds all the project references in the tree? Also what error do you see? Can you check your gitignore file too

                                                                              – Srayan Guhathakurta
                                                                              Mar 21 at 23:13







                                                                            2




                                                                            2





                                                                            Does not work for me, with git 2.7.

                                                                            – Bruno Haible
                                                                            Mar 20 at 21:27





                                                                            Does not work for me, with git 2.7.

                                                                            – Bruno Haible
                                                                            Mar 20 at 21:27













                                                                            Do you have something like an Everything sln file which adds all the project references in the tree? Also what error do you see? Can you check your gitignore file too

                                                                            – Srayan Guhathakurta
                                                                            Mar 21 at 23:13





                                                                            Do you have something like an Everything sln file which adds all the project references in the tree? Also what error do you see? Can you check your gitignore file too

                                                                            – Srayan Guhathakurta
                                                                            Mar 21 at 23:13











                                                                            1














                                                                            I think you'll have to write a script to do this. To be honest, I might install python to do it so that you can use os.walk to cd to each directory and issue the appropriate commands. Using python or some other scripting language, other than batch, would allow you to easily add/remove subprojects with out having to modify the script.






                                                                            share|improve this answer





























                                                                              1














                                                                              I think you'll have to write a script to do this. To be honest, I might install python to do it so that you can use os.walk to cd to each directory and issue the appropriate commands. Using python or some other scripting language, other than batch, would allow you to easily add/remove subprojects with out having to modify the script.






                                                                              share|improve this answer



























                                                                                1












                                                                                1








                                                                                1







                                                                                I think you'll have to write a script to do this. To be honest, I might install python to do it so that you can use os.walk to cd to each directory and issue the appropriate commands. Using python or some other scripting language, other than batch, would allow you to easily add/remove subprojects with out having to modify the script.






                                                                                share|improve this answer













                                                                                I think you'll have to write a script to do this. To be honest, I might install python to do it so that you can use os.walk to cd to each directory and issue the appropriate commands. Using python or some other scripting language, other than batch, would allow you to easily add/remove subprojects with out having to modify the script.







                                                                                share|improve this answer












                                                                                share|improve this answer



                                                                                share|improve this answer










                                                                                answered Jun 23 '09 at 4:04









                                                                                baudtackbaudtack

                                                                                18k5 gold badges48 silver badges60 bronze badges




                                                                                18k5 gold badges48 silver badges60 bronze badges
























                                                                                    1














                                                                                    Remark: not too easy way, but workable and it has its own unique pros.



                                                                                    If one want to clone only HEAD revision of a repository and only HEADs of all the its submodules (i.e. to checkout "trunk"), then one can use following Lua script. Sometimes simple command git submodule update --init --recursive --remote --no-fetch --depth=1 can result in an unrecoverable git error. In this case one need to clean up subdirectory of .git/modules directory and clone submodule manually using git clone --separate-git-dir command. The only complexity is to find out URL, path of .git directory of submodule and path of submodule in superproject tree.



                                                                                    Remark: the script is only tested against https://github.com/boostorg/boost.git repository. Its peculiarities: all the submodules hosted on the same host and .gitmodules contains only relative URLs.



                                                                                    -- mkdir boost ; cd boost ; lua ../git-submodules-clone-HEAD.lua https://github.com/boostorg/boost.git .
                                                                                    local module_url = arg[1] or 'https://github.com/boostorg/boost.git'
                                                                                    local module = arg[2] or module_url:match('.+/([_%d%a]+)%.git')
                                                                                    local branch = arg[3] or 'master'
                                                                                    function execute(command)
                                                                                    print('# ' .. command)
                                                                                    return os.execute(command)
                                                                                    end
                                                                                    -- execute('rm -rf ' .. module)
                                                                                    if not execute('git clone --single-branch --branch master --depth=1 ' .. module_url .. ' ' .. module) then
                                                                                    io.stderr:write('can't clone repository from ' .. module_url .. ' to ' .. module .. 'n')
                                                                                    return 1
                                                                                    end
                                                                                    -- cd $module ; git submodule update --init --recursive --remote --no-fetch --depth=1
                                                                                    execute('mkdir -p ' .. module .. '/.git/modules')
                                                                                    assert(io.input(module .. '/.gitmodules'))
                                                                                    local lines =
                                                                                    for line in io.lines() do
                                                                                    table.insert(lines, line)
                                                                                    end
                                                                                    local submodule
                                                                                    local path
                                                                                    local submodule_url
                                                                                    for _, line in ipairs(lines) do
                                                                                    local submodule_ = line:match('^%[submodule %"([_%d%a]-)%"%]$')
                                                                                    if submodule_ then
                                                                                    submodule = submodule_
                                                                                    path = nil
                                                                                    submodule_url = nil
                                                                                    else
                                                                                    local path_ = line:match('^%s*path = (.+)$')
                                                                                    if path_ then
                                                                                    path = path_
                                                                                    else
                                                                                    submodule_url = line:match('^%s*url = (.+)$')
                                                                                    end
                                                                                    if submodule and path and submodule_url then
                                                                                    -- execute('rm -rf ' .. path)
                                                                                    local git_dir = module .. '/.git/modules/' .. path:match('^.-/(.+)$')
                                                                                    -- execute('rm -rf ' .. git_dir)
                                                                                    execute('mkdir -p $(dirname "' .. git_dir .. '")')
                                                                                    if not execute('git clone --depth=1 --single-branch --branch=' .. branch .. ' --separate-git-dir ' .. git_dir .. ' ' .. module_url .. '/' .. submodule_url .. ' ' .. module .. '/' .. path) then
                                                                                    io.stderr:write('can't clone submodule ' .. submodule .. 'n')
                                                                                    return 1
                                                                                    end
                                                                                    path = nil
                                                                                    submodule_url = nil
                                                                                    end
                                                                                    end
                                                                                    end





                                                                                    share|improve this answer





























                                                                                      1














                                                                                      Remark: not too easy way, but workable and it has its own unique pros.



                                                                                      If one want to clone only HEAD revision of a repository and only HEADs of all the its submodules (i.e. to checkout "trunk"), then one can use following Lua script. Sometimes simple command git submodule update --init --recursive --remote --no-fetch --depth=1 can result in an unrecoverable git error. In this case one need to clean up subdirectory of .git/modules directory and clone submodule manually using git clone --separate-git-dir command. The only complexity is to find out URL, path of .git directory of submodule and path of submodule in superproject tree.



                                                                                      Remark: the script is only tested against https://github.com/boostorg/boost.git repository. Its peculiarities: all the submodules hosted on the same host and .gitmodules contains only relative URLs.



                                                                                      -- mkdir boost ; cd boost ; lua ../git-submodules-clone-HEAD.lua https://github.com/boostorg/boost.git .
                                                                                      local module_url = arg[1] or 'https://github.com/boostorg/boost.git'
                                                                                      local module = arg[2] or module_url:match('.+/([_%d%a]+)%.git')
                                                                                      local branch = arg[3] or 'master'
                                                                                      function execute(command)
                                                                                      print('# ' .. command)
                                                                                      return os.execute(command)
                                                                                      end
                                                                                      -- execute('rm -rf ' .. module)
                                                                                      if not execute('git clone --single-branch --branch master --depth=1 ' .. module_url .. ' ' .. module) then
                                                                                      io.stderr:write('can't clone repository from ' .. module_url .. ' to ' .. module .. 'n')
                                                                                      return 1
                                                                                      end
                                                                                      -- cd $module ; git submodule update --init --recursive --remote --no-fetch --depth=1
                                                                                      execute('mkdir -p ' .. module .. '/.git/modules')
                                                                                      assert(io.input(module .. '/.gitmodules'))
                                                                                      local lines =
                                                                                      for line in io.lines() do
                                                                                      table.insert(lines, line)
                                                                                      end
                                                                                      local submodule
                                                                                      local path
                                                                                      local submodule_url
                                                                                      for _, line in ipairs(lines) do
                                                                                      local submodule_ = line:match('^%[submodule %"([_%d%a]-)%"%]$')
                                                                                      if submodule_ then
                                                                                      submodule = submodule_
                                                                                      path = nil
                                                                                      submodule_url = nil
                                                                                      else
                                                                                      local path_ = line:match('^%s*path = (.+)$')
                                                                                      if path_ then
                                                                                      path = path_
                                                                                      else
                                                                                      submodule_url = line:match('^%s*url = (.+)$')
                                                                                      end
                                                                                      if submodule and path and submodule_url then
                                                                                      -- execute('rm -rf ' .. path)
                                                                                      local git_dir = module .. '/.git/modules/' .. path:match('^.-/(.+)$')
                                                                                      -- execute('rm -rf ' .. git_dir)
                                                                                      execute('mkdir -p $(dirname "' .. git_dir .. '")')
                                                                                      if not execute('git clone --depth=1 --single-branch --branch=' .. branch .. ' --separate-git-dir ' .. git_dir .. ' ' .. module_url .. '/' .. submodule_url .. ' ' .. module .. '/' .. path) then
                                                                                      io.stderr:write('can't clone submodule ' .. submodule .. 'n')
                                                                                      return 1
                                                                                      end
                                                                                      path = nil
                                                                                      submodule_url = nil
                                                                                      end
                                                                                      end
                                                                                      end





                                                                                      share|improve this answer



























                                                                                        1












                                                                                        1








                                                                                        1







                                                                                        Remark: not too easy way, but workable and it has its own unique pros.



                                                                                        If one want to clone only HEAD revision of a repository and only HEADs of all the its submodules (i.e. to checkout "trunk"), then one can use following Lua script. Sometimes simple command git submodule update --init --recursive --remote --no-fetch --depth=1 can result in an unrecoverable git error. In this case one need to clean up subdirectory of .git/modules directory and clone submodule manually using git clone --separate-git-dir command. The only complexity is to find out URL, path of .git directory of submodule and path of submodule in superproject tree.



                                                                                        Remark: the script is only tested against https://github.com/boostorg/boost.git repository. Its peculiarities: all the submodules hosted on the same host and .gitmodules contains only relative URLs.



                                                                                        -- mkdir boost ; cd boost ; lua ../git-submodules-clone-HEAD.lua https://github.com/boostorg/boost.git .
                                                                                        local module_url = arg[1] or 'https://github.com/boostorg/boost.git'
                                                                                        local module = arg[2] or module_url:match('.+/([_%d%a]+)%.git')
                                                                                        local branch = arg[3] or 'master'
                                                                                        function execute(command)
                                                                                        print('# ' .. command)
                                                                                        return os.execute(command)
                                                                                        end
                                                                                        -- execute('rm -rf ' .. module)
                                                                                        if not execute('git clone --single-branch --branch master --depth=1 ' .. module_url .. ' ' .. module) then
                                                                                        io.stderr:write('can't clone repository from ' .. module_url .. ' to ' .. module .. 'n')
                                                                                        return 1
                                                                                        end
                                                                                        -- cd $module ; git submodule update --init --recursive --remote --no-fetch --depth=1
                                                                                        execute('mkdir -p ' .. module .. '/.git/modules')
                                                                                        assert(io.input(module .. '/.gitmodules'))
                                                                                        local lines =
                                                                                        for line in io.lines() do
                                                                                        table.insert(lines, line)
                                                                                        end
                                                                                        local submodule
                                                                                        local path
                                                                                        local submodule_url
                                                                                        for _, line in ipairs(lines) do
                                                                                        local submodule_ = line:match('^%[submodule %"([_%d%a]-)%"%]$')
                                                                                        if submodule_ then
                                                                                        submodule = submodule_
                                                                                        path = nil
                                                                                        submodule_url = nil
                                                                                        else
                                                                                        local path_ = line:match('^%s*path = (.+)$')
                                                                                        if path_ then
                                                                                        path = path_
                                                                                        else
                                                                                        submodule_url = line:match('^%s*url = (.+)$')
                                                                                        end
                                                                                        if submodule and path and submodule_url then
                                                                                        -- execute('rm -rf ' .. path)
                                                                                        local git_dir = module .. '/.git/modules/' .. path:match('^.-/(.+)$')
                                                                                        -- execute('rm -rf ' .. git_dir)
                                                                                        execute('mkdir -p $(dirname "' .. git_dir .. '")')
                                                                                        if not execute('git clone --depth=1 --single-branch --branch=' .. branch .. ' --separate-git-dir ' .. git_dir .. ' ' .. module_url .. '/' .. submodule_url .. ' ' .. module .. '/' .. path) then
                                                                                        io.stderr:write('can't clone submodule ' .. submodule .. 'n')
                                                                                        return 1
                                                                                        end
                                                                                        path = nil
                                                                                        submodule_url = nil
                                                                                        end
                                                                                        end
                                                                                        end





                                                                                        share|improve this answer













                                                                                        Remark: not too easy way, but workable and it has its own unique pros.



                                                                                        If one want to clone only HEAD revision of a repository and only HEADs of all the its submodules (i.e. to checkout "trunk"), then one can use following Lua script. Sometimes simple command git submodule update --init --recursive --remote --no-fetch --depth=1 can result in an unrecoverable git error. In this case one need to clean up subdirectory of .git/modules directory and clone submodule manually using git clone --separate-git-dir command. The only complexity is to find out URL, path of .git directory of submodule and path of submodule in superproject tree.



                                                                                        Remark: the script is only tested against https://github.com/boostorg/boost.git repository. Its peculiarities: all the submodules hosted on the same host and .gitmodules contains only relative URLs.



                                                                                        -- mkdir boost ; cd boost ; lua ../git-submodules-clone-HEAD.lua https://github.com/boostorg/boost.git .
                                                                                        local module_url = arg[1] or 'https://github.com/boostorg/boost.git'
                                                                                        local module = arg[2] or module_url:match('.+/([_%d%a]+)%.git')
                                                                                        local branch = arg[3] or 'master'
                                                                                        function execute(command)
                                                                                        print('# ' .. command)
                                                                                        return os.execute(command)
                                                                                        end
                                                                                        -- execute('rm -rf ' .. module)
                                                                                        if not execute('git clone --single-branch --branch master --depth=1 ' .. module_url .. ' ' .. module) then
                                                                                        io.stderr:write('can't clone repository from ' .. module_url .. ' to ' .. module .. 'n')
                                                                                        return 1
                                                                                        end
                                                                                        -- cd $module ; git submodule update --init --recursive --remote --no-fetch --depth=1
                                                                                        execute('mkdir -p ' .. module .. '/.git/modules')
                                                                                        assert(io.input(module .. '/.gitmodules'))
                                                                                        local lines =
                                                                                        for line in io.lines() do
                                                                                        table.insert(lines, line)
                                                                                        end
                                                                                        local submodule
                                                                                        local path
                                                                                        local submodule_url
                                                                                        for _, line in ipairs(lines) do
                                                                                        local submodule_ = line:match('^%[submodule %"([_%d%a]-)%"%]$')
                                                                                        if submodule_ then
                                                                                        submodule = submodule_
                                                                                        path = nil
                                                                                        submodule_url = nil
                                                                                        else
                                                                                        local path_ = line:match('^%s*path = (.+)$')
                                                                                        if path_ then
                                                                                        path = path_
                                                                                        else
                                                                                        submodule_url = line:match('^%s*url = (.+)$')
                                                                                        end
                                                                                        if submodule and path and submodule_url then
                                                                                        -- execute('rm -rf ' .. path)
                                                                                        local git_dir = module .. '/.git/modules/' .. path:match('^.-/(.+)$')
                                                                                        -- execute('rm -rf ' .. git_dir)
                                                                                        execute('mkdir -p $(dirname "' .. git_dir .. '")')
                                                                                        if not execute('git clone --depth=1 --single-branch --branch=' .. branch .. ' --separate-git-dir ' .. git_dir .. ' ' .. module_url .. '/' .. submodule_url .. ' ' .. module .. '/' .. path) then
                                                                                        io.stderr:write('can't clone submodule ' .. submodule .. 'n')
                                                                                        return 1
                                                                                        end
                                                                                        path = nil
                                                                                        submodule_url = nil
                                                                                        end
                                                                                        end
                                                                                        end






                                                                                        share|improve this answer












                                                                                        share|improve this answer



                                                                                        share|improve this answer










                                                                                        answered Nov 21 '15 at 19:49









                                                                                        OrientOrient

                                                                                        6,4536 gold badges38 silver badges103 bronze badges




                                                                                        6,4536 gold badges38 silver badges103 bronze badges


















                                                                                            protected by Baba Jul 23 '13 at 9:17



                                                                                            Thank you for your interest in this question.
                                                                                            Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                                                                                            Would you like to answer one of these unanswered questions instead?



                                                                                            Popular posts from this blog

                                                                                            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                                                                                            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                                                                                            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript