How to Execute git Command on Multiple Git Repositories

I explain How to Execute git command on multiple git repositories.

You list directories using ls command.

ls

An example of the output:

bind            en_dbixcustom     en_webapp                   mojolicious
c               en_deeplearning   en_webdesign                perlzemi
centos          en_giblog         giblog                      philosophy
datascience     en_git            giblog_docjp                staff
dbixcustom      en_linux          giblog_new_blog_example     text
deeplearning    en_mariadb        giblog_new_website_example  ubuntu
devel           en_mojolicious    giblog_theme1               webapp
en_bind         en_perlzemi       git                         webdesign
en_c            en_philosophy     linux
en_centos       en_siliconvalley  mariadb
en_datascience  en_ubuntu         mojodoc

You can select the list of the directories using grep command.

ls | grep -P '^en_'

An example of the output:

en_bind
en_c
en_centos
en_datascience
en_dbixcustom
en_deeplearning
en_giblog
en_git
en_linux
en_mariadb
en_mojolicious
en_perlzemi
en_philosophy
en_siliconvalley
en_ubuntu
en_webapp
en_webdesign

You can make these directries the operand of the command option "git -C" using xargs command.

# git status
ls | grep -P '^en' | xargs -IFILE git -C FILE status

# git reset --hard
ls | grep -P '^en' | xargs -IFILE git -C FILE reset --hard

# git diff
ls | grep -P '^en' | xargs -IFILE git -C FILE --no-pager diff

# git add
ls | grep -P '^en' | xargs -IFILE git -C FILE add .

# git commit
ls | grep -P '^en' | xargs -IFILE git -C FILE commit -m "Add the links to English Pages"

# git push
ls | grep -P '^en' | xargs -IFILE git -C FILE push origin main

Associated Information