Skip to content

Instantly share code, notes, and snippets.

@bgamari
Created December 8, 2015 17:35
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 bgamari/919e1279c1615b9b1cb4 to your computer and use it in GitHub Desktop.
Save bgamari/919e1279c1615b9b1cb4 to your computer and use it in GitHub Desktop.
#!/bin/bash -e
usage() {
echo "Usage: $0 [<ref>]"
echo
echo "Make the submodules in a repository match the given ref (e.g. a commit, branch, or tag)."
exit 1
}
ref="$1"
if [ -z "$ref" ]; then ref="master"; fi
sha="$(git rev-parse $ref)" || usage
echo "Checking out submodules for $ref ($sha)"
git submodule foreach "(git -C \$toplevel checkout $sha \$path && git -C \$toplevel add \$path) || exit 0"
echo "Done."
git status
echo "Changes for preceeding submodules are staged, run 'git commit' to commit."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment