kojiromike

rebase-pr

0
0
# Install this skill:
npx skills add kojiromike/dot-claude --skill "rebase-pr"

Install specific skill from multi-skill repository

# Description

This skill should be used when the user asks to "rebase my PR", "rebase onto main", "update my branch", "fix merge conflicts", "resolve conflicts", "sync with main", or needs to bring a feature branch up to date with its base branch.

# SKILL.md


name: rebase-pr
description: This skill should be used when the user asks to "rebase my PR", "rebase onto main", "update my branch", "fix merge conflicts", "resolve conflicts", "sync with main", or needs to bring a feature branch up to date with its base branch.
version: 1.0.0


Rebase PR

Fetch the base branch, rebase the current PR onto it, and resolve any conflicts.

Prerequisites

Ensure the working directory is clean before starting:

git status --porcelain

If there are uncommitted changes, stash or commit them first.

Workflow

1. Determine the base branch

Get the PR's base branch from GitHub:

gh pr view --json baseRefName --jq '.baseRefName'

If not on a PR branch, default to main or master (check which exists on the remote).

2. Fetch the latest from origin

git fetch origin

3. Start the rebase

git rebase origin/<base-branch>

If the rebase succeeds with no conflicts, proceed to step 5.

4. Resolve conflicts (if any)

When conflicts occur, git will pause and report conflicting files.

For each conflicting file:

  1. Read the file to understand the conflict markers (<<<<<<<, =======, >>>>>>>)
  2. Analyze both versions:
  3. HEAD (above =======): The incoming changes from base branch
  4. Below =======: The current branch's changes
  5. Resolve intelligently:
  6. If both changes are independent, keep both
  7. If changes overlap, merge the intent of both versions
  8. If one supersedes the other, keep the correct version
  9. Edit the file to remove conflict markers and produce correct code
  10. Stage the resolved file: git add <file>

After resolving all conflicts in a commit:

git rebase --continue

Repeat until the rebase completes.

5. Verify the result

Confirm the branch is now ahead of the base:

git log --oneline origin/<base-branch>..HEAD

Run any relevant tests or checks to ensure the rebase didn't break anything.

6. Force push (with lease)

git push --force-with-lease

Conflict Resolution Strategies

Code conflicts

  • Understand what each side was trying to accomplish
  • Preserve the intent of both changes when possible
  • Test the merged result

Import/dependency conflicts

  • Include all necessary imports from both sides
  • Remove duplicates
  • Ensure import order follows project conventions

Lock file conflicts (package-lock.json, yarn.lock, composer.lock)

Do not manually resolve. Instead:

git checkout --theirs <lockfile>
git add <lockfile>

Then regenerate after rebase completes:

# npm
npm install

# yarn
yarn install

# composer
composer install

Migration conflicts (sequential migrations)

If two migrations have the same sequence number:
- Renumber one to be sequential
- Ensure the final state is correct

Aborting

If the rebase becomes too complex or produces incorrect results:

git rebase --abort

This returns the branch to its pre-rebase state.

Notes

  • Always use --force-with-lease instead of --force to avoid overwriting changes pushed by others
  • If unsure about a conflict resolution, ask the user before proceeding
  • After rebase, CI may need to re-run on the updated branch

# Supported AI Coding Agents

This skill is compatible with the SKILL.md standard and works with all major AI coding agents:

Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.