rebase-main
Scannednpx machina-cli add skill flurdy/agent-skills/rebase-main --openclawRebase onto Main
Rebase the current feature branch onto the latest main branch.
Usage
/rebase-main
Instructions
1. Check Current State
# Get current branch
git branch --show-current
# Check for uncommitted changes
git status --porcelain
If there are uncommitted changes, ask the user whether to:
- Stash them before rebasing
- Commit them first
- Abort the rebase
2. Fetch Latest Main
git fetch origin main
3. Check if Rebase is Needed
# See how many commits main is ahead
git rev-list --count HEAD..origin/main
If main is not ahead, inform the user the branch is already up to date.
4. Perform Rebase
git rebase origin/main
5. Handle Conflicts
If conflicts occur:
-
List the conflicting files:
git diff --name-only --diff-filter=U -
For each conflicting file:
- Read the file to understand the conflict
- Resolve the conflict appropriately
- Stage the resolved file:
git add {file}
-
Continue the rebase:
git rebase --continue -
If conflicts are too complex, offer to abort:
git rebase --abort
6. Force Push (if branch was already pushed)
# Check if branch has upstream
git rev-parse --abbrev-ref @{upstream} 2>/dev/null
# If it does, force push with lease for safety
git push --force-with-lease
7. Report Result
Tell the user:
- How many commits were rebased
- Whether force push was needed
- Any conflicts that were resolved
Source
git clone https://github.com/flurdy/agent-skills/blob/main/skills/rebase-main/SKILL.mdView on GitHub Overview
Rebase-main rebases the current feature branch on top of origin/main to incorporate the latest changes. This keeps history linear and reduces merge noise, ensuring your work remains compatible with the updated main. It covers prep steps, conflict handling, and safe pushing.
How This Skill Works
The skill fetches the latest main, checks if a rebase is needed, and then runs git rebase origin/main. If conflicts arise, resolve them using the files listed by git diff --name-only --diff-filter=U, continue with git rebase --continue, or abort if it’s too complex. After a successful rebase you may push with --force-with-lease if the branch has an upstream.
When to Use It
- Your feature branch is behind main after updates to main
- Before opening a PR to merge into main to ensure compatibility
- A hotfix was applied to main and you need those changes
- Your branch has diverged from main and needs a linear history
- You want to maintain a clean, up-to-date feature branch before merge
Quick Start
- Step 1: Check current branch and uncommitted changes, stash or commit if needed
- Step 2: Fetch origin main and run git rebase origin/main
- Step 3: Resolve any conflicts, git rebase --continue, and push with --force-with-lease if there is an upstream
Best Practices
- Check for uncommitted changes and stash or commit before rebasing
- Fetch origin/main to ensure you’re rebasing onto the latest main
- Verify that main is ahead with a rev-list count and only rebase if needed
- Resolve conflicts carefully, test the result, and continue the rebase
- If you have an upstream, push with --force-with-lease to update the remote safely
Example Use Cases
- A feature branch that needs to incorporate several commits from main after a release
- A hotfix on main requires your feature to rebase on top of updated code
- Conflicts arise in a single file; you resolve and continue the rebase
- Rebase is too complex in a feature branch; you abort and reassess
- Remote tracking exists; you push with --force-with-lease after successful rebase