From 91c3f7754f3865499cb05dc09bc15a17f4feb080 Mon Sep 17 00:00:00 2001 From: Joel Beckmeyer Date: Wed, 4 Feb 2026 10:05:58 -0500 Subject: [PATCH] support rebasing existing branch --- dot_local/bin/executable_xxbranch | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/dot_local/bin/executable_xxbranch b/dot_local/bin/executable_xxbranch index 57a3c72..a0ad993 100644 --- a/dot_local/bin/executable_xxbranch +++ b/dot_local/bin/executable_xxbranch @@ -1,10 +1,27 @@ #!/bin/sh -if [ $# -eq 1 ]; then - branch=$1 - git fetch upstream master - git checkout upstream/master - git checkout -b "$branch" -else - echo "Please specify new branch." +set -eu + +if [ $# -ne 1 ]; then + echo "Usage: $(basename "$0") " >&2 + exit 2 fi +branch="$1" +base_remote="upstream" +base_branch="master" +base_ref="$base_remote/$base_branch" + +# avoid rebasing with a dirty tree +if ! git diff --quiet || ! git diff --cached --quiet; then + echo "Working tree has uncommitted changes; commit/stash first." >&2 + exit 2 +fi + +git fetch "$base_remote" "$base_branch" + +if git show-ref --verify --quiet "refs/heads/$branch"; then + git checkout "$branch" + git rebase "$base_ref" +else + git checkout -b "$branch" "$base_ref" +fi