]> piware.de Git - bin.git/commitdiff
git-rebase-remote: Add master
authorMartin Pitt <martin@piware.de>
Fri, 9 Jan 2026 06:07:16 +0000 (07:07 +0100)
committerMartin Pitt <martin@piware.de>
Fri, 9 Jan 2026 06:07:16 +0000 (07:07 +0100)
git-rebase-remote [new file with mode: 0755]

diff --git a/git-rebase-remote b/git-rebase-remote
new file mode 100755 (executable)
index 0000000..00c5b27
--- /dev/null
@@ -0,0 +1,33 @@
+#!/bin/bash
+set -euo pipefail
+
+if [ $# -ne 1 ]; then
+    echo "Usage: git rebase-remote <remote/branch>" >&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"