Skip to content

Instantly share code, notes, and snippets.

@hmedkouri
Last active October 9, 2019 08:49
Show Gist options
  • Save hmedkouri/659e80ea4cbfea8bcc97e4cfde688c64 to your computer and use it in GitHub Desktop.
Save hmedkouri/659e80ea4cbfea8bcc97e4cfde688c64 to your computer and use it in GitHub Desktop.
Execute git command on all subdirectories - useful for git repos
#!/bin/sh
# store the command and its paramters
CMD="$@"
# store the current dir
CUR_DIR=$(pwd)
# Let the person running the script know what's going on.
echo -e "\n\033[1mExecuting \033[0;32m'$CMD'\033[0m\033[1m against all repositories under $CUR_DIR ...\033[0m\n"
# Find all git repositories and execute the given command
for i in $(find . -name ".git" | sort -n | cut -c 3-); do
echo "";
# We have to go to the .git parent directory to call the command
cd "$i";
cd ..;
echo "\033[33m ${PWD##*/} \033[0m";
# finally evaluate the command
eval $CMD;
# lets get back to the CUR_DIR
cd $CUR_DIR
done
echo -e "\n\033[32mComplete!\033[0m\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment