From ff14e9779518c60d9fe2321945a17fdd39a6e2ff Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 28 Aug 2021 06:43:24 +0200 Subject: Adding git tools. Signed-off-by: Daniel Baumann --- git/bin/git-checkout-branches | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 git/bin/git-checkout-branches (limited to 'git/bin/git-checkout-branches') diff --git a/git/bin/git-checkout-branches b/git/bin/git-checkout-branches new file mode 100755 index 0000000..5b1ef15 --- /dev/null +++ b/git/bin/git-checkout-branches @@ -0,0 +1,29 @@ +#!/bin/sh + +set -e + +CURRENT_BRANCH="$(git branch --show-current)" +REMOTE_BRANCHES="$(git branch -r | awk '{ print $1 }')" + +for REMOTE_BRANCH in ${REMOTE_BRANCHES} +do + BRANCH="$(echo "${REMOTE_BRANCH}" | cut -d/ -f 2-)" + + case "${BRANCH}" in + HEAD) + continue + ;; + esac + + if git branch | grep -Eq "^ *${BRANCH}$" + then + continue + fi + + git checkout -b "${BRANCH}" "${REMOTE_BRANCH}" +done + +if [ "$(git branch --show-current)" != "${CURRENT_BRANCH}" ] +then + git checkout "${CURRENT_BRANCH}" +fi -- cgit v1.2.3