Skip to content

Instantly share code, notes, and snippets.

@ginkgomzd
Created November 12, 2019 23:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ginkgomzd/46cf4d4f67918912d462e578c1104ded to your computer and use it in GitHub Desktop.
Save ginkgomzd/46cf4d4f67918912d462e578c1104ded to your computer and use it in GitHub Desktop.
bash function (such as you might put in .bash_aliases) to perform git commands on nested repos
#!/bin/bash
gitsubs() {
gitsubs_max_depth=12
echo searching for git repos
echo directory max-depth = $gitsubs_max_depth
echo executing git $@
( # use a subshell and change the field-separator
# to allow for spaces in filenames
IFS=$'\n'
for d in `find . -maxdepth $gitsubs_max_depth -type d`
do
pushd $d >/dev/null;
# if directory contains a .git dir OR if is a bare-repo:
if [[ -d .git || $d == *.git && $(basename $d) != .git ]]; then
echo ".,.,.,.,. \\><((((*> [ $d ] <*))))></ "; echo
git $@;
echo ""
fi
popd &>/dev/null
done
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment