]> git.wh0rd.org Git - home.git/commitdiff
git-rb-all: helper for rebasing all branches
authorMike Frysinger <vapier@gentoo.org>
Sun, 7 Jan 2018 21:36:01 +0000 (16:36 -0500)
committerMike Frysinger <vapier@gentoo.org>
Sun, 7 Jan 2018 21:36:01 +0000 (16:36 -0500)
.bin/git-rb-all [new file with mode: 0755]

diff --git a/.bin/git-rb-all b/.bin/git-rb-all
new file mode 100755 (executable)
index 0000000..839d143
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/bash
+# Helper to rewrite all local branches.
+
+rb_one() {
+       local b=$1
+
+       echo "### ${b}"
+       git checkout -q "${b}" || exit
+       if ! git rebase ; then
+               git rebase --abort
+       fi
+}
+
+usage() {
+       cat <<EOF
+Usage: rb-all
+EOF
+       exit 1
+}
+
+main() {
+       if [[ $# -ne 0 ]] ; then
+               usage
+       fi
+
+       local orig b branches
+       orig=$(git rev-parse --abbrev-ref HEAD) || return
+
+       branches=( $(git ls-remote . 'heads/*' | sed 's:.*refs/heads/::') )
+       for b in "${branches[@]}" ; do
+               rb_one "${b}"
+       done
+
+       git checkout -q "${orig}"
+}
+main "$@"