bash: gc: set default branch programatically

Signed-off-by: Michael Grote <michael.grote@posteo.de>
This commit is contained in:
Michael Grote 2023-12-07 16:06:36 +01:00
parent 61d46d5652
commit 95a5492483

View file

@ -150,11 +150,11 @@ EOF
*)
if [ ! -z $1 ] ; then
(echo ">>> Try local checkout" && git checkout --quiet "$1" > /dev/null 2>&1) ||
(echo ">>> Try remote checkout" && git checkout --quiet -b "$1" origin/"$1" > /dev/null 2>&1 || echo ">>> Unkown branch!")
(echo ">>> Try remote checkout" && git checkout --quiet -b "$1" origin/"$1" > /dev/null 2>&1 || echo ">>> Unknown branch!")
else
(git checkout --quiet master > /dev/null 2>&1 && echo '>>> Try checking out master') ||
(git checkout --quiet main > /dev/null 2>&1 && echo '>>> Try checking out main') ||
(git checkout --quiet release > /dev/null 2>&1 && echo '>>> Try checking out release')
echo ">>> get default branch"
default_branch=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p')
git checkout --quiet ${default_branch} > /dev/null 2>&1
fi
esac
}