Skip to content

Instantly share code, notes, and snippets.

@exaV
Created December 30, 2021 09:40
Show Gist options
  • Save exaV/7ce6b56b9ac1d15e290f0b50d98dc2df to your computer and use it in GitHub Desktop.
Save exaV/7ce6b56b9ac1d15e290f0b50d98dc2df to your computer and use it in GitHub Desktop.
run a git command in all subdirectories
# output path to child directories which contain a .git folder
alias findgitdirs='find . -maxdepth 2 -type d -name ".git" | sed -e "s|/.git||"'
gitall(){
# execute the argument as a git command in all (git) subdirectories
# if there are no arguments then print all of the directorries that would be used
if [ "$#" -eq 0 ]; then findgitdirs; return; fi
findgitdirs | xargs -I{} git -C {} "$@"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment