Skip to content

Instantly share code, notes, and snippets.

@HuakunShen
Created January 9, 2023 23:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HuakunShen/5d746ae1ff72f028a2f3a8795c3983a1 to your computer and use it in GitHub Desktop.
Save HuakunShen/5d746ae1ff72f028a2f3a8795c3983a1 to your computer and use it in GitHub Desktop.
Update and commit all submodules in one command.
#!/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
@HuakunShen
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment