From coding
Squash-merges a local branch or linked git worktree into the branch currently checked out in this repository, then removes the merged worktree (if any) and deletes the merged local branch. Use when the user says "merge <branch>", "merge this worktree", "squash merge and clean up", or asks to fold a feature branch/worktree into the current trunk branch.
How this skill is triggered — by the user, by Claude, or both
Slash command
/coding:git-mergeThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
| Variable | Value | Notes |
| Variable | Value | Notes |
|---|---|---|
| CURRENT_BRANCH | Branch checked out in the invocation worktree | Merge destination; often main |
| SOURCE_INPUT | User-supplied branch name or linked worktree | Exactly one source is required |
| WORKTREE_LIST_CMD | git worktree list --porcelain | Source of truth for linked worktree metadata |
| GIT_OPERATION_FILES | MERGE_HEAD, REBASE_HEAD, CHERRY_PICK_HEAD, REVERT_HEAD, BISECT_LOG | Files that indicate an in-progress git operation |
| MERGE_BASE | git merge-base <current-branch> <source> | Start of the source-only commit range |
| SOURCE_COMMIT_RANGE | <merge-base>..<source-branch> | Commits to preserve in the squash commit body |
| COMMIT_MESSAGE_SECTION | Squashed commits: | Heading for the preserved source commit log in the commit body |
SOURCE_INPUT resolves to exactly one local source branchCURRENT_BRANCH is different from the source branchSOURCE_INPUT as a worktree path by normalising it with realpath and matching it against WORKTREE_LIST_CMD output.SOURCE_INPUT resolves to a worktree path, derive the branch from the adjacent branch refs/heads/<name> entry in the porcelain output.SOURCE_INPUT as a local branch with git show-ref --verify --quiet refs/heads/<name>.SOURCE_INPUT is a branch name, still scan WORKTREE_LIST_CMD output for a linked worktree on that branch so it can be validated and removed during cleanup.A worktree is clean only when both of the following are true:
git status --porcelain returns no outputGIT_OPERATION_FILES existMERGE_BASE with git merge-base <current-branch> <source-branch>.SOURCE_COMMIT_RANGE as <merge-base>..<source-branch>.git log --reverse --format='- [%h] %s' <merge-base>..<source-branch> so the squash body preserves a concise chronological list of source commits.SOURCE_COMMIT_RANGE, not a generic Squash merge ... message.feat, fix, or perf over lower-signal maintenance types such as chore, docs, or test when the branch clearly contains product changes.task, preserve that convention.COMMIT_MESSAGE_SECTION heading, then the concise bullet list for SOURCE_COMMIT_RANGE in chronological order.git merge --squash --no-commit <source-branch>.git branch -D <source-branch> after successful merge/no-op handling and after removing any linked worktree.Entry state: RESOLVE_SOURCE
SOURCE_INPUT exactly matches a linked worktree path after normalisation
→ VERIFY_CURRENT_WORKTREESOURCE_INPUT resolves to an existing local branch
→ VERIFY_CURRENT_WORKTREESOURCE_INPUT must be an existing local branch or linked worktree pathCURRENT_BRANCH
→ STOP with error: source and target branch must differMERGE_BASE, capture SOURCE_COMMIT_RANGE, and draft the semantic squash commit messageCURRENT_BRANCH using the resolved source branchHEAD with git reset --hard HEADCURRENT_BRANCH with git symbolic-ref --quiet --short HEAD. Fail if HEAD is detached.git rev-parse --show-toplevel.WORKTREE_LIST_CMD output once and reuse it throughout the run.SOURCE_INPUT in this order:
a. Normalise it with realpath.
b. If the normalised path exactly matches a worktree entry from the porcelain output, record that as the source worktree path and extract its refs/heads/<name> branch.
c. Otherwise verify refs/heads/<SOURCE_INPUT> exists locally and record <SOURCE_INPUT> as the source branch.git status --porcelain; it must return nothing.GIT_OPERATION_FILES:
a. Resolve its path with git rev-parse --git-path <name>.
b. Fail if that path exists.CHECK_WORKTREE_CLEAN in the current worktree.CURRENT_BRANCH.CHECK_WORKTREE_CLEAN in the source worktree context by prefixing commands with git -C <source-worktree>.Compute MERGE_BASE with git merge-base <CURRENT_BRANCH> <source-branch>.
Capture the source-only history with git log --reverse --format='- [%h] %s' <MERGE_BASE>..<source-branch>.
Review the commit subjects and bodies in that range and infer the best semantic subject line for the squash commit:
a. Prefer the highest-signal change type represented by the branch, such as feat, fix, perf, or another repo-appropriate semantic type like task when that is the dominant convention.
b. If the branch contains mixed commits, summarise the overall user-facing outcome rather than echoing an implementation detail.
c. Keep the subject short, imperative, and specific.
Build the final commit message in this shape:
<semantic-subject>
Squashed commits:
- [short-sha] commit subject
- [short-sha] commit subject
Preserve every commit from the source-only range in the body as a concise - [short-sha] subject list.
If the source-only range is empty, still continue; the merge may become a verified no-op and skip commit creation.
HEAD with git reset --hard HEAD.git merge --squash --no-commit <source-branch> from the current worktree.RESET_TARGET and stop with the merge error.git diff --cached --quiet:
a. If it exits non-zero, staged changes exist; continue to COMMIT_SQUASH.
b. If it exits zero, no staged changes exist; treat the merge as a no-op and continue to cleanup.git commit -F <message-file>.RESET_TARGET and stop.git worktree remove <source-worktree>.--force; a dirty worktree should have failed earlier.git branch -D <source-branch>.- [short-sha] subject formatCURRENT_BRANCH to perform the mergegit worktree remove --forcegit branch -D after a successful squash merge or verified no-op merge pathVerify all of the following before reporting success:
git symbolic-ref --quiet --short HEAD still equals CURRENT_BRANCHgit status --porcelain in the current worktree is emptyrefs/heads/<source-branch>git worktree list --porcelaingit log -1 --format=%s is a semantic/conventional-style subject inferred from the source history rather than a generic squash messagegit log -1 --format=%B contains the Squashed commits: section followed by the preserved chronological - [short-sha] subject list from MERGE_BASE..source-branchCreates, edits, and optimizes skills for Claude Code, including drafting, evaluating with test prompts, iterating on performance, and improving skill descriptions for better triggering accuracy.
npx claudepluginhub codethread/agents --plugin coding