Skip to content

Instantly share code, notes, and snippets.

@tbl3rd
Last active August 29, 2015 14:24
Show Gist options
  • Save tbl3rd/ad9b58df35428ab91f11 to your computer and use it in GitHub Desktop.
Save tbl3rd/ad9b58df35428ab91f11 to your computer and use it in GitHub Desktop.
Run a git command on all repos in a directory tree.
#!/bin/bash
function help {
local dogit="$1"
local lines=(
"$dogit: Run a git command on all repos in a directory tree."
""
"Usage: $dogit <directory> [<command> ...]"
""
"Where: <directory> is the root of a tree of git repos."
" <command> is some git command verb such as 'pull'."
" ... is 0 or more arguments to <command>."
""
"Example: Fetch all repos in and under the current directory."
""
" # $dogit . fetch -v"
""
"Note: $dogit depends on a repo containing a '.git' directory"
" at its root, so it skips what are called 'bare' repos."
" Put your bare repos somewhere else -- like a git server."
" $dogit uses whatever 'git' command it finds in your path.")
for line in "${lines[@]}"
do
echo "$line" 1>&2
done
}
dogit="${0##*/}"
directory="$1"
shift
test -z "$directory" && help "$dogit" && exit 1
find "$directory" -type d -name '.git' -print |
while read git
do
cd "$git/.."
echo $dogit: In ${git%/.git} 1>&2
git "$@"
cd -
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment