Git - easy way pull latest of all submodules?

For git 1.6.1 or above you can use something similar to (modified to suit).

For git 1.6.1 or above you can use something similar to (modified to suit): git submodule foreach git pull See git-submodule(1) for details.

Great that's what I needed. Note though that when using msys-git in a Window's command prompt you need something later than v1.5.6. I had to upgrade to 1.6.3 to get it to work.

Thanks again. – Brad Robinson Jun 24 '09 at 1:26 5 This didn't work for me until ... origin master is specified (see the answer below) – Sridhar Ratnakumar Oct 6 '10 at 16:37 1 As it says, you need to modify the executed command to suit your needs. I've set it up to fetch whatever the current branch is tracking and rebase it onto the current branch, which is a pretty handy thing to have set up :) – Henrik Gustafsson Oct 6 '10 at 19:02 1 Now here's a question for you: Can you make that so it is recursive?I.e.

Git submodule foreach also gets run in each submodule EDIT: nvm, just use --recurse-submodules – conradev Jul 30 '11 at 2:36 2 Probably you should use git submodule update --recursive nowadays. – DASKAjA Sep 30 '11 at 14:12.

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.

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

For each repo listed, cd into it's directory and run git checkout master && git pull. Check for errors. 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.

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.

The following worked for me on Windows. Git submodule init git submodule update.

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.

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

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

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.

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

If you need to pull stuff for submodules into your submodule repositories use git pull --recurse-submodules a feature git 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.

Upvoted, I use this: alias update_submodules='git pull --recurse-submodules && git submodule update' – Stephen C Dec 6 '11 at 22:41.

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.

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.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions