Added the qbra command to display branches of current git repo and submodules.

Pascal J. Bourguignon [2021-07-19 14:49]
Added the qbra command to display branches of current git repo and submodules.

This displays a table all the current branches of the current
directory and all the git submodules.
The star indicates whether the branch is the current checkout
otherwise, the current checkout is a detached HEAD commit.
Filename
qbra
diff --git a/qbra b/qbra
new file mode 100755
index 0000000..4d7f2a3
--- /dev/null
+++ b/qbra
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+# This displays a table all the current branches of the current
+# directory and all the git submodules.
+# The star indicates whether the branch is the current checkout
+# otherwise, the current checkout is a detached HEAD commit.
+
+find . -name .git -print \
+    | sort \
+    | while read git ; do
+    dir="${git/\/.git/}"
+    ( cd "$dir"
+      printf "%-40s " "$dir"
+      branch=$(git branch --list|grep -e '^\*')
+      if [[ "$branch" =~ HEAD\ detached\ at\ ([0-9a-f]+) ]] ; then
+          printf '%s\n' "$(git branch --list -a --contains "${BASH_REMATCH[1]}" \
+              | grep -v 'HEAD detached' \
+              | head -n 1 \
+              | sed -e 's-remotes/--')"
+      else
+          printf '%s\n' "$branch"
+      fi
+    )
+done
+
ViewGit