diff --git a/cook.sh b/cook.sh index 105c6b1010977a80f2ca2a981a6a23f010e5d9a0..72b36d446b1dbb0931a88890e1db6e444631571c 100755 --- a/cook.sh +++ b/cook.sh @@ -119,14 +119,17 @@ function op { git remote add upstream "$GIT_UPSTREAM" git fetch upstream fi + + ORIGIN_BRANCH="$(git branch --remotes | grep '^ origin/HEAD -> ' | cut -d ' ' -f 5-)" if [ -n "$BRANCH" ] then - git checkout "$BRANCH" - else - #TODO: Find correct upstream default branch - git checkout master + ORIGIN_BRANCH="origin/$BRANCH" + fi + + if [ "$(git rev-parse HEAD)" != "$(git rev-parse $ORIGIN_BRANCH)" ] + then + git checkout -B "$(echo "$ORIGIN_BRANCH" | cut -d / -f 2-)" "$ORIGIN_BRANCH" fi - git pull git submodule sync --recursive git submodule update --init --recursive popd > /dev/null