Skip to content

Instantly share code, notes, and snippets.

@thvitt
Created April 25, 2016 09:38
Show Gist options
  • Save thvitt/7e13a54341acff295fefd7f051f5b79c to your computer and use it in GitHub Desktop.
Save thvitt/7e13a54341acff295fefd7f051f5b79c to your computer and use it in GitHub Desktop.
Recursively checkout branches of the same name from a git module and its submodules
#!/bin/bash
export SUBDIRECTORY_OK=1
dashless=$(basename "$0" | sed -e 's/-/ /')
OPTIONS_SPEC="$dashless [-p] [branch]
$dashless looks through the issue's commit message and code for for referenced
issues and opens the configured chili project info for them. Use 'git config
chili.url' to configure the root url.
--
p,pull also pull
"
. "$(git --exec-path)/git-sh-setup"
pull=
branch=$(git symbolic-ref --short HEAD)
echo "$@"
while [ $# -gt 0 ]; do
opt="$1"
shift
case "$opt" in
-p) pull=1 ;;
--) break ;;
*) die_with_status 129 "Unexpected option: $opt"
esac
done
if [ $# -gt 0 ]; then
branch="$1"
fi
require_work_tree_exists
cd_to_toplevel
export pull branch
git checkout "$branch"
if [ \! -z \"$pull\" ] ; then
git pull ;
fi;
git submodule foreach "
git checkout \"$branch\";
if [ \! -z \"$pull\" ] ; then
git pull ;
fi;
:
"
git status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment