Merge Worktree Branch with Squash Merge

VerifiedCaution

Squash merge a worktree branch into the target branch (default main) and auto-generate a conventional commit message. Handles worktree validation, conflict detection, and cleanup.

Sby Skills Guide Bot
DevelopmentIntermediate
7/28/2026
Claude Code
#git-worktree#squash-merge#conventional-commits#branch-management#codex-swarm

Recommended for

Automated summary

Squash-merges a Git worktree branch into a target branch (main or master) and automatically writes a conventional commit message based on an analysis of the diff.

Strengths

  • Reads the full diff and changed files before composing the commit message (dominant type, grouped changes)
  • Strict context validation: confirms it runs inside a worktree, requires a clean tree, and flags WIP commits
  • Halts on merge conflicts instead of attempting risky automatic resolution
  • Automatically removes the worktree and branch afterwards, with awareness of codex-swarm directories

Limitations

  • Manual invocation only (disable-model-invocation), so Claude will not trigger it on its own
  • Assumes a specific target branch convention (main, falling back to master) and does not handle multiple remotes
  • The final cleanup deletes the worktree and branch, so unmerged or unpushed work is lost
When to use it

Use it when finished work in a Git worktree should land on main as one clean commit, especially after a codex-swarm run.

When not to use it

Avoid it when you need the branch's detailed commit history preserved or when complex merge conflicts are expected.

Security analysis

Caution
Quality score85/100

This is a legitimate git automation skill, but it uses powerful repository-mutating commands and automatically cleans up worktrees/branches. There is no exfiltration, obfuscation, or destructive system-level behavior, but the broad write access and cleanup steps warrant caution.

Findings
  • •Runs git commands that modify repository state, including checkout, squash merge, and commit in the original repo.
  • •Automatically removes the worktree and deletes the branch with `git worktree remove` and `git branch -d` without explicit user confirmation.
  • •Checks clean working-tree state only in the worktree, not in the original repository, before checking out the target branch there.
  • •Performs a network `git fetch origin <target>`.
How this analysis is made

Examples

Merge current worktree
/merge-worktree main
Collect swarm results
Collect the results of the codex-swarm worktrees and squash-merge each one into main.
Squash into develop
Squash-merge this worktree branch into develop with a conventional commit message.

name: merge-worktree description: "워크트리 브랜치를 main으로 squash-merge + conventional commit 자동 생성. codex-swarm 워크트리 자동 인식. '머지해', 'merge worktree', '워크트리 머지', '결과 수집', 'squash merge' 요청에 사용." argument-hint: "[target-branch]" disable-model-invocation: true

Merge Worktree

워크트리 브랜치를 대상 브랜치로 squash-merge하고 conventional commit 메시지를 자동 작성한다.

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

Phase 1: Validation

  1. Worktree 확인: git rev-parse --git-dir 출력에 /worktrees/가 포함되어야 한다. 아니면 중지.

  2. 현재 브랜치 확인: git branch --show-current

  3. 대상 브랜치 결정:

    • $ARGUMENTS가 있으면 해당 브랜치 사용
    • 없으면 main 존재 확인, 없으면 master
  4. 원본 레포 경로 확인: git rev-parse --git-common-dir의 부모 디렉토리

  5. 클린 상태 확인: git status --porcelain이 비어있어야 한다. 미커밋 변경이 있으면 먼저 커밋/스태시 안내.

Phase 2: Research

  1. 커밋 이력: git log --oneline <target>..HEAD

  2. 변경 파일 요약: git diff <target>...HEAD --stat

  3. 전체 diff: git diff <target>...HEAD — 꼼꼼히 읽는다.

  4. 핵심 파일 읽기: 가장 큰 변경, 신규 파일, 삭제 파일을 Read로 확인.

  5. 변경 분류:

    • Features (신규 기능)
    • Fixes (버그 수정)
    • Refactors (구조 변경)
    • Tests (테스트)
    • Docs (문서)
    • Config/Chore (빌드, CI, 의존성)
  6. dominant type 결정: feat, fix, refactor, docs, chore, test 중 하나

Phase 3: 대상 브랜치 준비

  1. 대상 브랜치 최근 커밋 확인: git -C <원본레포> log --oneline -10 <target>

  2. WIP 커밋 감지: wip:, auto-commit, WIP 시작 커밋이 있으면 사용자에게 경고.

  3. 최신 fetch: git -C <원본레포> fetch origin <target> 2>/dev/null

Phase 4: Squash Merge

  1. 대상 브랜치 checkout:

    git -C <원본레포> checkout <target>
    
  2. squash merge 실행:

    git -C <원본레포> merge --squash <워크트리브랜치>
    
  3. 충돌 처리: 충돌 발생 시 충돌 파일 목록 + 마커를 보여주고 중지. 자동 해결 시도 금지.

Phase 5: 커밋 메시지 작성 + 커밋

Phase 2 분석 기반으로 아래 구조의 커밋 메시지를 작성한다:

<type>: <명령형 요약, 72자 이내, 마침표 없음>

<무엇을 왜 했는지 2-4문장. 동기와 접근 방식 중심.>

Changes:
* <그룹별 변경 사항>
* <하위 항목은 서브 불릿>

규칙:

  • <type>은 feat, fix, refactor, docs, chore, test 중 하나
  • 여러 유형이 섞이면 dominant 사용
  • 요약: 명령형 ("add", "fix", "refactor"), 마침표 없음, 72자 제한
  • 본문: 왜와 맥락, 무엇만이 아님
  • Changes: 관련 항목 그룹핑, 중요한 것 먼저
  • Co-Authored-By 푸터 절대 추가 금지 (글로벌 설정 includeCoAuthoredBy: false)

커밋 실행:

git -C <원본레포> commit -m "$(cat <<'EOF'
<커밋 메시지>
EOF
)"

Phase 6: 정리 + 검증

  1. 커밋 확인: git -C <원본레포> log --oneline -3

  2. 워크트리 자동 정리:

    git -C <원본레포> worktree remove <워크트리경로>
    git -C <원본레포> branch -d <워크트리브랜치>
    
  3. codex-swarm 정리 감지: 워크트리 경로가 .codex-swarm/wt-* 패턴이면:

    • 같은 .codex-swarm/ 디렉토리에 다른 워크트리가 남아있는지 확인
    • 모든 워크트리가 머지 완료되었으면 .codex-swarm/ 전체 정리 제안
    • git worktree prune 실행
  4. 결과 보고:

    • 커밋 해시 + 요약
    • 머지 대상 브랜치
    • 워크트리 정리 완료 여부
    • push 안내 (git push)

codex-swarm 연동

이 스킬은 tfx-codex-swarm의 Step 10 "결과 수집"에서 자동으로 호출된다. codex-swarm이 완료한 각 워크트리에 대해 순차적으로 실행:

각 워크트리에 대해:
  1. 워크트리로 cd
  2. /merge-worktree main
  3. 다음 워크트리로 이동

주의사항

  • force-push, destructive 연산은 사용자 확인 없이 절대 실행 금지
  • pre-commit hook 건너뛰기(--no-verify) 금지
  • 예상치 못한 상황이면 추측하지 말고 중지 후 설명

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/merge-worktree-branch-with-squash-merge-ms47vq0g/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/merge-worktree-branch-with-squash-merge-ms47vq0g' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/merge-worktree-branch-with-squash-merge-ms47vq0g/download' --output '.skill-downloads/merge-worktree-branch-with-squash-merge-ms47vq0g/SKILL.md.part' && mv '.skill-downloads/merge-worktree-branch-with-squash-merge-ms47vq0g/SKILL.md.part' '.skill-downloads/merge-worktree-branch-with-squash-merge-ms47vq0g/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/merge-worktree-branch-with-squash-merge-ms47vq0g/SKILL.md' && test -s '.skill-downloads/merge-worktree-branch-with-squash-merge-ms47vq0g/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/merge-worktree' && cp -R '.skill-downloads/merge-worktree-branch-with-squash-merge-ms47vq0g' '.claude/skills/merge-worktree'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/merge-worktree-branch-with-squash-merge-ms47vq0g'

openskills read 'merge-worktree-branch-with-squash-merge-ms47vq0g'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/merge-worktree-branch-with-squash-merge-ms47vq0g/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills