mj-agent-git-delete

Deletes Git branches and worktrees with dual-remote cleanup and safety confirmations.

1|Updated Mar 4, 2026
One-click install
npx skills add https://github.com/MJ-AgentLab/mj-agent --skill mj-agent-git-delete-mj-agentlab
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: mj-agent-git-delete
Source: https://github.com/MJ-AgentLab/mj-agent/tree/main/.claude/skills/mj-agent-git-delete
Command: npx skills add https://github.com/MJ-AgentLab/mj-agent --skill mj-agent-git-delete-mj-agentlab

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Deleting Git branches and worktrees after a PR merge is error-prone: wrong deletion order, unmerged commits lost silently, stale remote state causing false merge detection, and accidental deletion of protected branches. This Skill enforces a safe, confirmed cleanup sequence for the mj-agent bare-repo worktree workflow. ## Core Features & Use Cases - Ordered deletion workflow: Removes worktree first, then local branch, then optionally both remotes (gitee and origin), with per-step failure isolation and a final cleanup summary. - Human-in-the-loop safety gates: Prompts for confirmation on uncommitted changes, unmerged commits (with remote-merge verification via tip commit lookup), wrong working directory, and missing remote branches. - Protected branch enforcement: Refuses to delete main and develop, and requires running worktree removal from a different worktree. - Use Case: After a hotfix branch is merged via PR, ask to clean it up; the Skill fetches remote state, asks whether to delete locally, remotely, or both, then executes the full sequence with confirmations. ## Quick Start Ask the assistant to delete the merged feature branch and its worktree, choosing whether to also remove the gitee and origin remote branches.

Frequently Asked Questions about mj-agent-git-delete

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I safely delete a Git branch and its worktree after a PR merge?▼

Fetch remote state first, then remove the worktree with git worktree remove, delete the local branch with git branch -d, and optionally delete remote branches. Run the worktree removal from a different worktree, never from inside the one being deleted.

How to delete a Git branch on multiple remotes like gitee and origin?▼

Push a delete to each remote separately: git push gitee --delete branch-name followed by git push origin --delete branch-name. Sync remote tracking state with git fetch --prune first so stale references do not mislead merge checks.

Why does git branch -d fail saying the branch is not fully merged?▼

This happens when local history lacks commits that were merged remotely, often via squash merge. Verify by checking whether the branch tip commit is contained in origin/develop; if it is, the branch is safe to force-delete with -D.

Can I delete the main or develop branch with this workflow?▼

No. Main and develop are protected branches and deletion requests for them are refused outright. The workflow only applies to feature, fix, hotfix, documentation, and similar working branches.

What happens if worktree removal leaves a residual directory on Windows?▼

Windows file locks can leave the directory behind even after git worktree remove clears the metadata. The workflow records the residual path, continues with branch and remote deletion, and flags the leftover directory for manual removal in the final summary.