cleanup-worktree

Fetch the latest main branch, detach HEAD, and delete the current working branch.

Updated Feb 10, 2026
One-click install
npx skills add https://github.com/mjbellantoni/scm-tools-claude --skill cleanup-worktree
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cleanup-worktree
Source: https://github.com/mjbellantoni/scm-tools-claude/tree/main/skills/cleanup-worktree
Command: npx skills add https://github.com/mjbellantoni/scm-tools-claude --skill cleanup-worktree

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill automates the process of cleaning up your local Git environment after a branch has been successfully merged into the main branch, preventing clutter and ensuring your local repository stays tidy.

Core Features & Use Cases

  • Automated Branch Deletion: Safely removes merged local branches.
  • Detached HEAD: Resets your working directory to the latest state of the main branch.
  • Use Case: After merging your feature branch into main and confirming the pull request is closed, you can use this skill to automatically delete the feature branch locally and reset your HEAD to the latest main.

Quick Start

Use the cleanup-worktree skill to clean up the current working branch after it has been merged.

Frequently Asked Questions about cleanup-worktree

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

FAQPage Schema
How do I clean up local Git branches after a merge?

This cleanup process fetches the latest main branch, detaches HEAD to that commit, and deletes the working branch to prevent repository clutter after a successful merge.

How does detached HEAD work when deleting a merged branch?

A detached HEAD resets your working directory to the latest main branch commit before deletion, ensuring your local repository safely anchors to the main codebase.

What is the best way to delete a local feature branch after a pull request is closed?

Automating the fetch of main, detaching HEAD, and safely removing the branch is the best way to delete a local feature branch and ensure your local repository stays tidy.

Is it safe to force delete a branch during post-merge Git worktree cleanup?

Post-merge Git worktree cleanup is safe because it attempts a safe delete first and only prompts for a force delete if necessary, preventing accidental loss of unmerged work.

Do I need any dependencies to automate local branch management in Git?

Automating local branch management in Git requires no additional dependencies, allowing you to safely remove merged branches and reset your HEAD directly within your existing workflow.