365Git

Month

March 2011

1 post

Git submodule foreach – updating many submodules at once

If you have a repository with many submodules, it’s easy to update them all at once.

For example: I have my vim dotfiles in a Git repository. Not only does this make it easier for me to keep my vim setup the same across multiple machines, but also lets me add other bundles as submodules which makes it easy to update the bundles and propagate changes.

Once in a while I go into the repository and run:

git submodule foreach 'git pull || :'

The foreach command evaluates a shell command in each of the submodules. In this case git pull. The || : (in bash this is ‘or true’) stops the foreach command from terminating because of a non-zero return from the shell command.

Or, you could avoid the zero return problem by echoing the return value:

git submodule foreach 'echo `git pull`'

This is just one use of foreach. Since I don’t actually develop the submodules, I can keep the repository tidy by running:

git submodule foreach 'echo `git gc --aggressive`'
Mar 5, 201121 notes
#git #submodule #repository #pull
Next page →
2010 2011
  • January 2
  • February 2
  • March 1
  • April 1
  • May
  • June
  • July
  • August
  • September
  • October
  • November 2
  • December
2010 2011
  • January
  • February
  • March 8
  • April 17
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December