Skip to content

Instantly share code, notes, and snippets.

Created July 4, 2010 18:07
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
# Shell Script for super-respositores that executes git on all sub-repositories
# Homepage at
# Licensed under the GPL
# Authors:
function usage {
appName=`basename $0`
echo "Welcome to $appName. It acts on all directories in your project as if they were sub-respositories. For most commands, you simply type what you would normally for git, however you simply type $appName with desired parameters in the super-repository root of your project. For example:"
echo "-- To clone, type '$appName -b DEV testbw' which will clone, then intiliaze + update submodules and checkout the master branch for each submodule"
echo "-- To diff, in the super repo root, type '$appName diff'"
echo "-- To commit, in the super repo root, type '$appName commit -a'"
echo "-- To pull, in the super repo root, type '$appName pull'"
echo "-- To push, in the super repo root, type '$appName push origin'"
function apush() {
var=$1; shift;
if [ -n "$var" ]; then
eval "$var+=(\"\$@\")"
function git_exec_subs {
echo "executing on all subrepositories: git $@"
for repo in $(find $rootDir -name ".git" -exec dirname {} \;); do
echo "# cd $repo; git $@"
cd "$repo"; git $@
case "$1" in
eval moduleName=\$$#
moduleName=`basename $moduleName`
if [ -z $moduleName ]; then
cloneParams="$cloneParams $moduleName"
echo $TOP_DIR
echo $1 to $moduleName;
git $cloneParams
git submodule init
git submodule update
for repo in $(find $TOP_DIR -name ".git" -exec dirname {} \;); do
git_exec_subs $repo submodule init
git_exec_subs $repo submodule update
git_exec_subs $repo checkout master
git_exec_subs `pwd` $@;
Copy link

spiderr commented Jul 4, 2010

Thanks Markus, the find for .git dirs is a much better plan, and get's all nested sub-repos nicely regardless of depth. I suppose this only handles one level of nested sub-repos. Somone smarter than I can figure out some awesome bash recursion to handle that efficiently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment