rebase-on-main
Skill6 starsChanged 4 months agoMITView on GitHub
Safely rebase the current Git branch onto the repository's mainline branch with backups, conflict analysis, validation, and force-with-lease pushing. Use when the user asks to rebase, sync, update, replay, or force-push a feature branch on top of main or master.
- Commits and pushes
In this repository14 other files it gives its agents.
- strict-code-reviewSkill
- fabro-workflowSkill
- fastapi-proSkill
- industry-standardizeSkill
- issue-decomposerSkill
- issue-triage-loopSkill
- martin-clean-codeSkill
- pr-code-reviewSkill
- prd-reviewSkill
- request-to-prdSkill
- startup-analystSkill
- two-axis-reviewSkill
- un-rgeSkill
- unslopSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
26 rules. About 0 are common, 16 are distinctive, and 10 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈16
Distinctive · estimate
This author's own choices. Worth a look.
10
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 10
Prefer safety over completion.
- Distinctive: line 11
Always create a backup before rewriting history.
- Very specific: line 12
Always use --force-with-lease, never --force.
- Distinctive: line 13
Do not rebase shared branches, protected branches, or branches with unknown ownership unless the user explicitly approves.
- Very specific: line 15
Before a normal rebase or git rebase --continue, set GIT_EDITOR=true.
- Very specific: line 45
Use origin/master instead of origin/main only when master is the repository mainline.
- Very specific: line 56
Run bash "$SKILL_DIR/scripts/pre-rebase-backup.sh" when available.
- Distinctive: line 65
If the working tree has unrelated uncommitted changes, stop and ask before stashing or modifying them.
- Distinctive: line 70
Use simple rebase for 1-2 straightforward commits.
- Distinctive: line 71
Use squash-first for 3+ commits or repeated conflicts if the user is willing to trade per-commit history for one conflict-resolution pass.
- Distinctive: line 72
Use interactive rebase when commit order, duplicate commits, or focused cleanup matters.
- Very specific: line 77
Use this only when the user explicitly asks to squash, or has accepted squashing.
- Distinctive: line 87
Run the backup helper before git reset --soft.
- Very specific: line 90
Prefer git rebase <target> where target is usually origin/main.
- Very specific: line 91
If conflicts occur, run bash "$SKILL_DIR/scripts/analyze-conflicts.sh" when available.
- Very specific: line 92
Read every conflicted file before editing.
- Distinctive: line 94
If the correct result is ambiguous, stop and ask the user rather than guessing.
- Very specific: line 99
Run bash "$SKILL_DIR/scripts/validate-merge.sh" when available.
- Distinctive: line 100
Run project-specific checks discovered from the repo, such as tests, lint, typecheck, or targeted tests for changed areas.
- Distinctive: line 101
If validation fails, fix the merged code before continuing or pushing.
- Very specific: line 105
If --force-with-lease fails, stop.
- Distinctive: line 109
Keep mainline fixes such as security, migrations, API changes, dependency updates, and bug fixes unless there is a clear reason not to.
- Distinctive: line 110
Keep feature-branch behavior that implements the user's work unless it is made obsolete by mainline.
- Distinctive: line 111
Remove duplicate code created by combining both sides.
- Distinctive: line 112
Add short comments only when the merged logic would otherwise be unclear.
- Distinctive: line 113
Do not continue a rebase with unresolved conflict markers, failing syntax checks, or unexplained test failures.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Rebase On Main
Non-Negotiables
- Prefer safety over completion. If resolving a conflict could overwrite work, remove functionality, or requires product/code intent you cannot infer, stop and ask the user a specific question.
- Always create a backup before rewriting history.
- Always use
--force-with-lease, never--force. - Do not rebase shared branches, protected branches, or branches with unknown ownership unless the user explicitly approves.
- Preserve functionality from both sides when possible. Never silently drop behavior from either mainline or the feature branch.
- Before a normal rebase or
git rebase --continue, setGIT_EDITOR=true. Keep it set through the rebase so Git accepts the existing commit message instead of opening vim, nano, or another interactive editor. - Report what changed at the end: target branch, commits rebased, conflicts resolved, validation run, and push result.
Locate Bundled Helpers
The scripts below belong to this skill, not to the repository being rebased. Before changing into the target repository, take the absolute path of this loaded SKILL.md from the harness's skill context and derive SKILL_DIR from it. Never run bash scripts/... from the target repository or hard-code a machine-specific skills directory.
# Substitute the absolute SKILL.md path reported by the current harness.
SKILL_FILE="<path reported for this loaded SKILL.md>"
SKILL_DIR="$(CDPATH= cd -- "$(dirname -- "$SKILL_FILE")" && pwd -P)"Confirm the helpers exist before invoking them. If the harness does not expose a skill path or a helper is unavailable, use the inline fallback in the relevant workflow step; do not stop solely to find the scripts.
Quick Start
export GIT_EDITOR=true
bash "$SKILL_DIR/scripts/pre-rebase-backup.sh"
git fetch origin
git rebase origin/main
bash "$SKILL_DIR/scripts/analyze-conflicts.sh"
# Resolve conflicts intelligently, then:
git add <resolved-files>
git rebase --continue
bash "$SKILL_DIR/scripts/validate-merge.sh"
git push origin "$(git rev-parse --abbrev-ref HEAD)" --force-with-leaseUse origin/master instead of origin/main only when master is the repository mainline.
Workflow
- Establish context:
- Run
git status --short --branch. - Save the current branch with
git rev-parse --abbrev-ref HEAD. - Refuse to proceed from detached HEAD.
- Identify mainline from
origin/HEAD, then fall back toorigin/main,origin/master,main, ormaster.
- Run
- Check safety:
Run
bash "$SKILL_DIR/scripts/pre-rebase-backup.sh"when available. Otherwise create the backup inline:branch="$(git rev-parse --abbrev-ref HEAD)" timestamp="$(date +%Y%m%d_%H%M%S)" safe_branch="$(printf '%s' "$branch" | tr '/[:space:]' '--')" backup="backup/rebase-${safe_branch}-${timestamp}" git branch "$backup"- If the working tree has unrelated uncommitted changes, stop and ask before stashing or modifying them.
- Fetch latest with
git fetch origin. - Inspect divergence with
git log --oneline <target>..HEADandgit log --oneline HEAD..<target>.
- Choose strategy:
- Use simple rebase for 1-2 straightforward commits.
- Use squash-first for 3+ commits or repeated conflicts if the user is willing to trade per-commit history for one conflict-resolution pass.
- Use interactive rebase when commit order, duplicate commits, or focused cleanup matters.
- See references/strategies.md.
Squash First
Use this only when the user explicitly asks to squash, or has accepted squashing. After fetching and selecting <target>, squash all feature commits since the merge base into one local commit, then rebase that commit onto the updated target:
base="$(git merge-base HEAD <target>)"
git log --oneline "$base"..HEAD
git reset --soft "$base"
git commit -m "<concise summary of the squashed feature>"
git rebase <target>Run the backup helper before git reset --soft. Do not use this path if the displayed range contains commits the user intends to retain separately. If the final message cannot be inferred from the commits, ask the user for it.
- Rebase:
- Prefer
git rebase <target>where target is usuallyorigin/main. - If conflicts occur, run
bash "$SKILL_DIR/scripts/analyze-conflicts.sh"when available; otherwise rungit diff --name-only --diff-filter=Uandgit status --short --branch. - Read every conflicted file before editing. Understand
oursandtheirsin rebase context before choosing. - Resolve by combining intent where possible; do not blindly choose either side.
- If the correct result is ambiguous, stop and ask the user rather than guessing.
- Stage resolved files and continue with
git rebase --continue. - Repeat until the rebase completes.
- Prefer
- Validate:
- Run
bash "$SKILL_DIR/scripts/validate-merge.sh"when available. Otherwise rungit diff --check, ensuregit diff --name-only --diff-filter=Uis empty, and inspect changed files for conflict markers. - Run project-specific checks discovered from the repo, such as tests, lint, typecheck, or targeted tests for changed areas.
- If validation fails, fix the merged code before continuing or pushing.
- Run
- Push:
- Push only after validation:
git push origin "$(git rev-parse --abbrev-ref HEAD)" --force-with-lease. - If
--force-with-leasefails, stop. Someone else may have pushed to the branch.
- Push only after validation:
Conflict Resolution Rules
- Keep mainline fixes such as security, migrations, API changes, dependency updates, and bug fixes unless there is a clear reason not to.
- Keep feature-branch behavior that implements the user's work unless it is made obsolete by mainline.
- Remove duplicate code created by combining both sides.
- Add short comments only when the merged logic would otherwise be unclear.
- Do not continue a rebase with unresolved conflict markers, failing syntax checks, or unexplained test failures.
Recovery
- Abort an unsafe rebase with
git rebase --abort. - Recover from the backup branch created by the helper or inline backup command.
- See references/troubleshooting.md for repeated conflicts, bad resolutions, and force-with-lease failures.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

