Compare local branch changes against the remote branch to detect rebase/merge mistakes.
Compare local branch changes against the remote branch to detect rebase/merge mistakes.
Determine the base branch in this order:
$ARGUMENTS if the user specifies a branchbin/base-branch if the script exists and is executabledevelopVerify the upstream tracking branch exists:
git rev-parse --verify @{u}
If this fails, report that there's no remote branch to compare against and stop. The user needs to push their branch first.
Ensure the tmp directory exists:
mkdir -p tmp
Fetch the latest remote refs, generate both diffs with zero context lines and ignoring whitespace changes, strip metadata lines, then compare:
git fetch origin
git diff -b --unified=0 <base-branch>...HEAD > tmp/local_branch_diff.patch
git diff -b --unified=0 origin/<base-branch>...@{u} > tmp/remote_branch_diff.patch
grep -v -E '^(index |@@ |diff --git)' tmp/local_branch_diff.patch > tmp/local_stripped.patch
grep -v -E '^(index |@@ |diff --git)' tmp/remote_branch_diff.patch > tmp/remote_stripped.patch
diff tmp/local_stripped.patch tmp/remote_stripped.patch > tmp/diff_comparison.patch || true
Read tmp/diff_comparison.patch.
If it's empty, report: Clean rebase — no issues detected. The local and remote branches make identical code changes relative to the base branch.
If there are differences, read the relevant source files for context and report:
Any difference warrants review. Read the source files to assess each one.
Signs of trouble:
+ line present in the remote diff but missing from local → an addition was lost during rebase- line present in the remote diff but missing from local → a deletion was lost, meaning removed code came backFor each difference:
rm -f tmp/local_branch_diff.patch tmp/remote_branch_diff.patch tmp/local_stripped.patch tmp/remote_stripped.patch tmp/diff_comparison.patch