Skip to content

Instantly share code, notes, and snippets.

@a-h-abid
Last active September 26, 2024 16:48
Show Gist options
  • Save a-h-abid/ede05904ab924aa634e8659ed66f3516 to your computer and use it in GitHub Desktop.
Save a-h-abid/ede05904ab924aa634e8659ed66f3516 to your computer and use it in GitHub Desktop.
Traverse across all directories in current path (excluding mentions) and run specified git command.
#!/usr/bin/env bash
# set -x
# Check if any arguments are passed
if [[ $# -eq 0 ]]; then
echo "No git commands provided."
exit 1
fi
gitCmds=("$@")
rootDir=$(pwd)
# Excluded directories (space-separated list)
EXCLUDED_DIRS=("dir1" "dir2")
# Get the list of directories, filter out the excluded ones & sort
DIRS=$(find . -maxdepth 1 -type d -printf "%f\n" | grep -v "^.$" | grep -vFf <(printf "%s\n" "${EXCLUDED_DIRS[@]}") | sort)
for dir in $DIRS; do
echo "================"
echo "Inside Dir: $dir"
cd "$rootDir/$dir" && git $gitCmds
echo
done
cd $rootDir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment