From git-utils
Merge the current branch's PR (squash) and clean up — delete branch, switch to default branch, pull, remove worktree if applicable. Use when user says "/merge-and-cleanup", "merge and cleanup", or "merge this PR".
How this skill is triggered — by the user, by Claude, or both
Slash command
/git-utils:merge-and-cleanupThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Merge the current branch's PR via squash merge, delete the remote branch, switch to main, pull, and clean up the worktree if applicable.
Merge the current branch's PR via squash merge, delete the remote branch, switch to main, pull, and clean up the worktree if applicable.
Run these commands to understand the current state:
# Get current branch
BRANCH=$(git branch --show-current)
echo "Branch: $BRANCH"
# Check if on main/master
DEFAULT_BRANCH=$(git remote show origin | sed -n 's/.*HEAD branch: //p')
if [ -z "$DEFAULT_BRANCH" ]; then
DEFAULT_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's|refs/remotes/origin/||')
fi
echo "Default branch: $DEFAULT_BRANCH"
# Check for uncommitted changes
git status --porcelain
# Check if in a worktree
GIT_DIR=$(git rev-parse --git-dir)
GIT_COMMON_DIR=$(git rev-parse --git-common-dir)
echo "git-dir: $GIT_DIR"
echo "git-common-dir: $GIT_COMMON_DIR"
DEFAULT_BRANCH is empty, report "Could not determine the default branch — check that the origin remote is configured" and stop.BRANCH equals DEFAULT_BRANCH (main/master), report "Already on the default branch, nothing to merge" and stop.git status --porcelain has output, warn the user about uncommitted changes and ask whether to proceed.GIT_DIR != GIT_COMMON_DIR, we're in a worktree. Note the current worktree path (pwd) and the main repo path (parent of GIT_COMMON_DIR).# Look up PR for this branch
gh pr view --json state,number,title,mergeStateStatus,statusCheckRollup
gh pr create. Stop.OPEN, tell the user the PR is already closed/merged. Stop.mergeStateStatus is BLOCKED or status checks are failing, warn the user and ask whether to proceed anyway.gh pr merge --squash --delete-branch
If the merge fails, report the error and stop. Note: when in a worktree, --delete-branch may warn about failing to delete the local branch (since it's checked out). This is expected — the local branch will be cleaned up when the worktree is removed in Step 4. Only treat it as a failure if the merge itself fails.
If NOT in a worktree:
git checkout $DEFAULT_BRANCH
git pull
If in a worktree:
Do NOT try to checkout inside the worktree. Instead, note that cleanup will happen next.
If we detected a worktree in Step 1:
Use git -C to operate on the main repo without relying on cd (which does not persist across Bash tool calls). Run these as a single chained command:
WORKTREE_PATH=$(pwd)
MAIN_REPO=$(git rev-parse --git-common-dir | sed 's|/\.git$||')
git -C "$MAIN_REPO" checkout "$DEFAULT_BRANCH" && \
git -C "$MAIN_REPO" pull && \
git -C "$MAIN_REPO" worktree remove "$WORKTREE_PATH" && \
git -C "$MAIN_REPO" worktree prune
Report the worktree path that was removed.
Report what was done:
gh pr create, stop--delete-branchnpx claudepluginhub ericboehs/claude-plugins --plugin git-utilsMerges reviewed PRs when triggered by /pr-merge or merge commands. Handles squash/rebase, worktrees, integration branches, and auto-merge for CI gating.
Verifies CI status, local tests, and repo safety before merging a PR, with post-merge health monitoring. Use when landing a completed implementation.
Guides creation, editing, and verification of skills for AI coding agents using test-driven development with subagent scenarios. Use when authoring or debugging skills.