agentleFS
andrewthetechieandrewthetechie/andrew-skills/skills/rebase-on-main/SKILL.md

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

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
  1. Distinctive:

    Prefer safety over completion.

    line 10
  2. Distinctive:

    Always create a backup before rewriting history.

    line 11
  3. Very specific:

    Always use --force-with-lease, never --force.

    line 12
  4. Distinctive:

    Do not rebase shared branches, protected branches, or branches with unknown ownership unless the user explicitly approves.

    line 13
  5. Very specific:

    Before a normal rebase or git rebase --continue, set GIT_EDITOR=true.

    line 15
  6. Very specific:

    Use origin/master instead of origin/main only when master is the repository mainline.

    line 45
  7. Very specific:

    Run bash "$SKILL_DIR/scripts/pre-rebase-backup.sh" when available.

    line 56
  8. Distinctive:

    If the working tree has unrelated uncommitted changes, stop and ask before stashing or modifying them.

    line 65
  9. Distinctive:

    Use simple rebase for 1-2 straightforward commits.

    line 70
  10. Distinctive:

    Use squash-first for 3+ commits or repeated conflicts if the user is willing to trade per-commit history for one conflict-resolution pass.

    line 71
  11. Distinctive:

    Use interactive rebase when commit order, duplicate commits, or focused cleanup matters.

    line 72
  12. Very specific:

    Use this only when the user explicitly asks to squash, or has accepted squashing.

    line 77
  13. Distinctive:

    Run the backup helper before git reset --soft.

    line 87
  14. Very specific:

    Prefer git rebase <target> where target is usually origin/main.

    line 90
  15. Very specific:

    If conflicts occur, run bash "$SKILL_DIR/scripts/analyze-conflicts.sh" when available.

    line 91
  16. Very specific:

    Read every conflicted file before editing.

    line 92
  17. Distinctive:

    If the correct result is ambiguous, stop and ask the user rather than guessing.

    line 94
  18. Very specific:

    Run bash "$SKILL_DIR/scripts/validate-merge.sh" when available.

    line 99
  19. Distinctive:

    Run project-specific checks discovered from the repo, such as tests, lint, typecheck, or targeted tests for changed areas.

    line 100
  20. Distinctive:

    If validation fails, fix the merged code before continuing or pushing.

    line 101
  21. Very specific:

    If --force-with-lease fails, stop.

    line 105
  22. Distinctive:

    Keep mainline fixes such as security, migrations, API changes, dependency updates, and bug fixes unless there is a clear reason not to.

    line 109
  23. Distinctive:

    Keep feature-branch behavior that implements the user's work unless it is made obsolete by mainline.

    line 110
  24. Distinctive:

    Remove duplicate code created by combining both sides.

    line 111
  25. Distinctive:

    Add short comments only when the merged logic would otherwise be unclear.

    line 112
  26. Distinctive:

    Do not continue a rebase with unresolved conflict markers, failing syntax checks, or unexplained test failures.

    line 113

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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, set GIT_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-lease

Use origin/master instead of origin/main only when master is the repository mainline.

Workflow

  1. 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 to origin/main, origin/master, main, or master.
  2. 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>..HEAD and git log --oneline HEAD..<target>.
  3. 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.

  1. Rebase:
    • Prefer git rebase <target> where target is usually origin/main.
    • If conflicts occur, run bash "$SKILL_DIR/scripts/analyze-conflicts.sh" when available; otherwise run git diff --name-only --diff-filter=U and git status --short --branch.
    • Read every conflicted file before editing. Understand ours and theirs in 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.
  2. Validate:
    • Run bash "$SKILL_DIR/scripts/validate-merge.sh" when available. Otherwise run git diff --check, ensure git diff --name-only --diff-filter=U is 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.
  3. Push:
    • Push only after validation: git push origin "$(git rev-parse --abbrev-ref HEAD)" --force-with-lease.
    • If --force-with-lease fails, stop. Someone else may have pushed to the branch.

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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.