Skip to content

Instantly share code, notes, and snippets.

@eeowaa
Last active March 29, 2019 16:01
Show Gist options
  • Save eeowaa/86b45f7c6c66f854e96f2b9e5d3031aa to your computer and use it in GitHub Desktop.
Save eeowaa/86b45f7c6c66f854e96f2b9e5d3031aa to your computer and use it in GitHub Desktop.
Perform a specific git operation on every repository residing in a child directory of the current working directory
#!/bin/sh
# XXX: Hack to get to the cwd of the parent process
test "X$GIT_PREFIX" = X || cd -- "$GIT_PREFIX"
# Only return 0 if *everything* succeeds
rc=0
# Output a nice header to separate this command from the others
cat <<EOF
-------------------------------------------------------------------------------
GIT BULK COMMAND STARTED: `date`
-------------------------------------------------------------------------------
EOF
# For each child directory containing a `.git' grandchild directory
ls -d */.git | while read x
do
test -d "$x" || continue
repo=`dirname "$x"`
echo >&2 "=== $repo ==="
# Navigate to that directory and do something!
cd "$repo" && {
git "$@" || rc=1
cd ..
} || rc=1
done
exit $rc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment