From: Martin Pitt Date: Fri, 9 Jan 2026 06:07:16 +0000 (+0100) Subject: git-rebase-remote: Add X-Git-Url: https://piware.de/gitweb/?a=commitdiff_plain;h=HEAD;p=bin.git git-rebase-remote: Add --- 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"