From 7480859f02b2faae4c711b49f76b6ff0d7369010 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Fri, 9 Jan 2026 07:07:16 +0100 Subject: [PATCH] git-rebase-remote: Add --- git-rebase-remote | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 git-rebase-remote diff --git a/git-rebase-remote b/git-rebase-remote new file mode 100755 index 0000000..00c5b27 --- /dev/null +++ b/git-rebase-remote @@ -0,0 +1,33 @@ +#!/bin/bash +set -euo pipefail + +if [ $# -ne 1 ]; then + echo "Usage: git rebase-remote " >&2 + exit 1 +fi + +remote_branch="$1" +remote="${remote_branch%%/*}" +branch="${remote_branch#*/}" + +if [ "$remote" = "$branch" ]; then + echo "Error: Could not parse remote/branch from '$remote_branch'" >&2 + exit 1 +fi + +# Save current branch/commit +current=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || git rev-parse HEAD) + +# Fetch both branches +git fetch "$remote" "$branch" +git fetch origin main + +# Checkout remote branch in detached HEAD state, rebase, and push +git checkout --detach "$remote/$branch" +git rebase origin/main +git push --force-with-lease "$remote" "HEAD:$branch" + +# Return to original branch/commit +git checkout "$current" + +echo "✓ Rebased and pushed $remote_branch" -- 2.47.3