home / skills / dyad-sh / dyad / pr-rebase

pr-rebase skill

/.claude/skills/pr-rebase

This skill rebases the current branch on the latest upstream changes, resolves conflicts, and pushes, saving time and ensuring a clean PR history.

npx playbooks add skill dyad-sh/dyad --skill pr-rebase

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
1.7 KB
---
name: dyad:pr-rebase
description: Rebase the current branch on the latest upstream changes, resolve conflicts, and push.
---

# PR Rebase

Rebase the current branch on the latest upstream changes, resolve conflicts, and push.

## Instructions

1. **Determine the git remote setup:**

   ```
   git remote -v
   git branch -vv
   ```

   In GitHub Actions for cross-repo PRs:
   - `origin` points to the **head repo** (fork) - this is where you push
   - `upstream` points to the **base repo** - this is what you rebase onto

   For same-repo PRs, `origin` points to the main repo and there may be no `upstream`.

2. **Fetch the latest changes:**

   ```
   git fetch --all
   ```

3. **Rebase onto the base branch:**

   Use `upstream/main` if the `upstream` remote exists (cross-repo PR), otherwise use `origin/main`:

   ```
   # Check if upstream remote exists
   git remote get-url upstream 2>/dev/null && git rebase upstream/main || git rebase origin/main
   ```

4. **If there are merge conflicts:**
   - Identify the conflicting files from the rebase output
   - Read each conflicting file and understand both versions of the changes
   - Resolve the conflicts by editing the files to combine changes appropriately
   - Stage the resolved files:

     ```
     git add <resolved-file>
     ```

   - Continue the rebase:

     ```
     git rebase --continue
     ```

   - Repeat until all conflicts are resolved and the rebase completes

5. **Run lint and push:**

   Run the `/dyad:pr-push` skill to run lint checks, fix any issues, and push the rebased branch.

6. **Summarize the results:**
   - Report that the rebase was successful
   - List any conflicts that were resolved
   - Note any lint fixes that were applied
   - Confirm the branch has been pushed

Overview

This skill rebases the current Git branch onto the latest upstream changes, helps resolve conflicts, and pushes the updated branch. It automates the fetch/rebase flow, guides conflict resolution, and hands off to a lint-and-push step. The goal is a clean, up-to-date PR branch ready to merge.

How this skill works

The skill checks your git remotes to decide whether to rebase onto upstream/main (cross-repo) or origin/main (same-repo). It fetches all refs, runs the rebase, and surfaces any file conflicts for manual resolution. After you stage resolved files and continue the rebase, it delegates linting and push operations to the pr-push step and summarizes the outcome.

When to use it

  • Before opening or updating a pull request to ensure it applies cleanly
  • When CI shows conflicts or merge errors with the target branch
  • When syncing a forked/head branch with changes from the base repository
  • Before running integration tests that assume latest upstream code
  • When preparing a PR for final review to minimize merge conflicts

Best practices

  • Confirm remote configuration with git remote -v and git branch -vv before rebasing
  • Always git fetch --all to ensure you rebase onto the absolute latest commits
  • Inspect each conflict carefully; prefer small, logical resolutions that preserve intent
  • Run the repository linting and tests after the rebase and before pushing
  • Use signed commits or include clear changelog entries if rebase rewrites history

Example use cases

  • A feature branch in a fork needs to rebase onto the main branch of the base repo before CI can pass
  • A same-repository PR falls behind main after a large merge and must be updated to remove conflicts
  • Resolving a conflict where upstream renamed a file while your branch modified it, then pushing the resolved branch
  • Preparing multiple dependent PRs by rebasing each on the updated base branch to preserve a clean commit history

FAQ

What remote do I rebase onto if there is no upstream?

If upstream is absent, the skill rebases onto origin/main by default.

What if I encounter repeated conflicts during rebase?

Resolve and stage each conflicting file, run git rebase --continue, and repeat until complete. Use git rebase --abort to return to the pre-rebase state if needed.