Created
January 9, 2023 23:26
-
-
Save HuakunShen/5d746ae1ff72f028a2f3a8795c3983a1 to your computer and use it in GitHub Desktop.
Update and commit all submodules in one command.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cwd=$PWD | |
submodulePaths=$(git submodule | awk '{$1=$1;print}' | cut -d ' ' -f 2) | |
function git_add_commit_update { | |
nothing=$(git status | grep 'nothing to commit') | |
if [[ -z $nothing ]]; then | |
git add . | |
git commit -m "Update Module" | |
git push | |
fi | |
} | |
for path in $submodulePaths | |
do | |
cd $path | |
detached_head=$(git branch | grep 'HEAD detached') | |
echo $path | |
if [[ -z $detached_head ]]; then | |
git_add_commit_update | |
else | |
git stash | |
git checkout master | |
git stash pop | |
git_add_commit_update | |
fi | |
cd $cwd | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When building a repo with many submodules, it's troublesome to commit for each repo. It's a good practice to have detailed commit for each repo, but in my case, I am taking notes (in markdown) using submodules. It's ok to have a simple 'Update' commit message.
This shell script basically commits all submodules with a change.