agentleFS
HyperAITeamHyperAITeam/CLITrigger/.claude/skills/merge-worktree/SKILL.md

merge-worktree

Skill14 starsChanged 7 months agoMITView on GitHub

Squash-merge the current worktree branch into the main branch (or a specified target). Analyzes git history and source code to craft a comprehensive commit message.

  • Commits and pushes

4 other projects use a version of this, 1 of them edited.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

15 rules. About 0 are common, 6 are distinctive, and 9 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 9

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Follow these phases exactly, in order.

    line 21
  2. Very specific:

    Verify worktree: Check if the current git directory is a worktree.

    line 27
  3. Very specific:

    If $ARGUMENTS is provided and non-empty, use it as the target branch.

    line 33
  4. Distinctive:

    Clean working tree: Run git status --porcelain.

    line 38
  5. Very specific:

    Commit history: Run git log --oneline <target>..HEAD to see all commits on this worktree branch.

    line 46
  6. Very specific:

    File change summary: Run git diff <target>...HEAD --stat to get an overview of what files changed and how much.

    line 48
  7. Very specific:

    Full diff: Run git diff <target>...HEAD to read the complete diff.

    line 50
  8. Very specific:

    Check target branch state: Run git -C <original-repo-path> log --oneline -10 <target> to see recent commits on the target branch.

    line 70
  9. Very specific:

    Detect stray WIP commits: If the target branch has commits that look like auto-generated WIP commits (e.g., messages starting with wip:, …

    line 72
  10. Distinctive:

    Handle conflicts: If the merge reports conflicts:

    line 90
  11. Distinctive:

    If the merge succeeds (no conflicts), proceed to Phase 5.

    line 96
  12. Distinctive:

    If changes span multiple types, use the dominant one

    line 119
  13. Very specific:

    Always end with Co-Authored-By

    line 123
  14. Very specific:

    Confirm the commit: Run git -C <original-repo-path> log --oneline -3 and show the result to the user.

    line 137
  15. Distinctive:

    If anything unexpected happens at any phase, stop and explain rather than guessing.

    line 152

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

Merge Worktree

Squash-merge the current worktree branch back into the target branch with a comprehensive, structured commit message.

Current context

  • Git dir: !git rev-parse --git-dir
  • Current branch: !git branch --show-current
  • Recent commits: !git log --oneline -20
  • Working tree status: !git status --short

Instructions

Follow these phases exactly, in order. Do NOT skip phases.


Phase 1: Validation

  1. Verify worktree: Check if the current git directory is a worktree. The output of git rev-parse --git-dir must contain /worktrees/. If it does not, stop immediately and tell the user:

    "This skill must be run from inside a git worktree. Use /worktree to create one first."

  2. Identify current branch: Get the worktree branch name from git branch --show-current.
  3. Resolve target branch:
    • If $ARGUMENTS is provided and non-empty, use it as the target branch.
    • Otherwise, detect the default branch: check if main exists, else check master. If neither exists, stop and ask the user.
  4. Identify the original repo path: Parse the original repo root from the git-dir path. The worktree's .git file points back to the main repo — use git rev-parse --git-common-dir to find it, then derive the original repo working directory (its parent).
  5. Clean working tree: Run git status --porcelain. If there are uncommitted changes, stop and tell the user to commit or stash them first.

Phase 2: Research

This is the most critical phase. You must deeply understand what was done before writing any commit message.

  1. Commit history: Run git log --oneline <target>..HEAD to see all commits on this worktree branch.
  2. File change summary: Run git diff <target>...HEAD --stat to get an overview of what files changed and how much.
  3. Full diff: Run git diff <target>...HEAD to read the complete diff. Study it carefully.
  4. Read key files: For the most significantly changed files (largest diffs, new files, deleted files), use the Read tool to understand the full context — not just the diff lines.
  5. Categorize changes: Mentally group all changes into categories:
    • Features (new functionality)
    • Fixes (bug corrections)
    • Refactors (code restructuring without behavior change)
    • Tests (new or updated tests)
    • Docs (documentation changes)
    • Config/Chore (build, CI, tooling, dependencies)
  6. Identify the dominant type: Determine which conventional commit type (feat, fix, refactor, docs, chore, test) best represents the overall body of work.

Phase 3: Target branch preparation

  1. Get the original repo path (from Phase 1 step 4).
  2. Check target branch state: Run git -C <original-repo-path> log --oneline -10 <target> to see recent commits on the target branch.
  3. Detect stray WIP commits: If the target branch has commits that look like auto-generated WIP commits (e.g., messages starting with wip:, auto-commit, WIP), warn the user and ask if they want to reset to the last clean commit before merging.
  4. Fetch latest (if remote exists): Run git -C <original-repo-path> fetch origin <target> 2>/dev/null to ensure target is up to date with remote. Do not fail if no remote.

Phase 4: Squash merge

  1. Ensure target branch is checked out in the original repo:
    git -C <original-repo-path> checkout <target>
  2. Perform the squash merge:
    git -C <original-repo-path> merge --squash <worktree-branch>
  3. Handle conflicts: If the merge reports conflicts:
    • List all conflicted files
    • Show the conflict markers
    • Stop and report to the user — do NOT attempt to auto-resolve
    • Tell them to resolve conflicts in the original repo and then run the skill again
  4. If the merge succeeds (no conflicts), proceed to Phase 5.

Phase 5: Craft commit message and commit

Based on your Phase 2 research, write the commit message following this exact structure:

<type>: <concise summary in imperative mood, under 72 chars, no period>

<2-4 sentence paragraph explaining what was done and WHY. Focus on the
motivation and high-level approach, not implementation details.>

Changes:
- <grouped bullet points of what changed>
- <use sub-bullets for details within a group>

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Rules:

  • <type> must be one of: feat, fix, refactor, docs, chore, test
  • If changes span multiple types, use the dominant one
  • Summary line: imperative mood ("add", "fix", "refactor"), no period, max 72 chars
  • Body paragraph: explain the why and context, not just what
  • Changes: group related items together, most important first
  • Always end with Co-Authored-By

Create the commit in the original repo using a heredoc:

git -C <original-repo-path> commit -m "$(cat <<'EOF'
<your commit message here>
EOF
)"

Phase 6: Verification

  1. Confirm the commit: Run git -C <original-repo-path> log --oneline -3 and show the result to the user.
  2. Report summary: Tell the user:
    • The final commit hash
    • The commit summary line
    • Which branch it was merged into
    • Remind them the worktree branch still exists — they can delete it with git worktree remove <path> if no longer needed
    • Remind them to git push if they want to push to the remote

Important notes

  • Never force-push or use destructive git operations without explicit user confirmation.
  • Never skip pre-commit hooks (--no-verify).
  • If anything unexpected happens at any phase, stop and explain rather than guessing.
  • The commit message quality is paramount — take time in Phase 2 to truly understand the changes.

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.