tags:

views:

1020

answers:

5

Hi,

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 dependant project as a submodule. During development, we often want to just go grab the latest version of every dependant submodule.

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

Thanks.

+2  A: 

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.

gahooa
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.
cantabilesoftware
A: 

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.

docgnome
+13  A: 

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

Henrik Gustafsson
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.
cantabilesoftware
This didn't work for me until `... origin master` is specified (see the answer below)
Sridhar Ratnakumar
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
+8  A: 

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.

A: 

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

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