From 3446f7851ab8c92e5dea973b974052393ac367c7 Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Wed, 8 Oct 2025 05:31:18 +0000 Subject: [PATCH] gitconfig: improve rbm alias base detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let rbm resolve master/main from local refs first, then fall back to the remote default branch chosen via origin/HEAD (including remote-only refs). Forward all user-supplied arguments to git rebase so the alias mirrors the native command’s behavior. --- gitconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitconfig b/gitconfig index 3309120..f268394 100644 --- a/gitconfig +++ b/gitconfig @@ -31,7 +31,7 @@ rba = rebase --abort rbc = rebase --continue rbi = rebase -i - rbm = "!fn(){ branch=''; if git show-ref --verify --quiet refs/heads/master; then branch='master'; elif git show-ref --verify --quiet refs/heads/main; then branch='main'; fi; if [ -n '$branch' ]; then git rebase $branch $1; else echo 'Both master and main branch not found!' >&2; return 1; fi; };fn" + rbm = "!fn(){ base=''; remote_head=$(git symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null || true); remote_branch=${remote_head#origin/}; if [ -n \"$remote_branch\" ] && [ \"$remote_branch\" != \"$remote_head\" ]; then case \"$remote_branch\" in master|main) if git show-ref --verify --quiet \"refs/heads/$remote_branch\"; then base=$remote_branch; elif git show-ref --verify --quiet \"refs/remotes/origin/$remote_branch\"; then base=origin/$remote_branch; fi;; esac; fi; if [ -z \"$base\" ] && git show-ref --verify --quiet refs/heads/master; then base=master; elif [ -z \"$base\" ] && git show-ref --verify --quiet refs/heads/main; then base=main; fi; if [ -z \"$base\" ] && [ -n \"$remote_branch\" ]; then if git show-ref --verify --quiet \"refs/heads/$remote_branch\"; then base=$remote_branch; elif [ -n \"$remote_head\" ] && git show-ref --verify --quiet \"refs/remotes/$remote_head\"; then base=$remote_head; fi; fi; if [ -z \"$base\" ]; then echo 'Both master and main branch not found!' >&2; return 1; fi; git rebase \"$base\" \"$@\"; };fn" rmt = remote rmtv = remote -v rmta = remote add