By using git add -A
and git commit -a
, I can obviously add/commit all changes to the repo I'm currently situated in. However, is there a way to include all submodules in an add/commit and apply the same commit message to each?
You can use an alias. Make script: e.g. ~/supercommit.sh
#!/bin/bash -e
if [ -z $1 ]; then
echo "You need to provide a commit message"
exit
fi
git submodule foreach git add -A .
git submodule foreach git commit -am "$1"
git add -A .
git commit -am "$1"
And mark it executable (chmod +x
). Now, create an alias:
git config alias.supercommit '!~/supercommit.sh "$@"; #'
That should do (I'll test it in a bit)
Well, this was asked and answered 9 years ago, and it helped me today when I was looking for the same thing. However, I faced some issues getting it working so I am posting this in order to help anyone else who may face the same issue.
issues :
fixes :
updated code
#!/bin/bash -e
if [ -z "$1" ]; then
echo "You need to provide a commit message"
exit
fi
git submodule foreach "
git add -A .
git update-index --refresh
commits=\$(git diff-index HEAD)
if [ ! -z \"\$commits\" ]; then
git commit -am \"$1\"
fi"
git add -A .
git commit -am "$1"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With