I tried all of the suggestions here, and none of them really worked for me for various reasons.
So here's what I have in my profile and I use it pretty often.
gitr () {
for f in $(find . -type d -name .git | awk -F"/.git$" '{print $1}'); do
echo
echo "................................ (cd $f && git $*) ........................................."
echo
(cd $f && git $*)
done
}
Snippets in code files are easily loaded in bash with the "." command, for instance:
. gitr.sh # file containing gitr() function, if not in a profile file
Then I can run
gitr status
And I get something like:
................................ (cd ./dir0 && git status) .........................................
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
................................ (cd ./dir1 && git status) .........................................
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
................................ (cd ./dir2 && git status) .........................................
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
................................ (cd . && git status) .........................................
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
or
gitr log -c 1
or
gitr rev-parse --abbrev-ref HEAD