git-branch-cleanup

Switch to main, rebase pull, and delete the original Git branch.

Updated Feb 14, 2026
One-click install
npx skills add https://github.com/Suniljit/personal-toolkit --skill git-branch-cleanup-suniljit
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: git-branch-cleanup
Source: https://github.com/Suniljit/personal-toolkit/tree/main/.opencode/skills/git-branch-cleanup
Command: npx skills add https://github.com/Suniljit/personal-toolkit --skill git-branch-cleanup-suniljit

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Switches from the current Git branch to main, pulls the latest changes with a rebase, and deletes the original branch, helping keep repositories clean and avoid stale feature branches.

Core Features & Use Cases

  • Safely switch from a feature branch to main with a rebase to incorporate upstream changes.
  • Delete the original feature branch only after confirming it has been merged and is safe to remove.
  • Provide clear user feedback about success or failure, with step-by-step error messages if something goes wrong.
  • Use Case: After a PR is merged, run this skill to automatically return to main and remove the feature branch.

Quick Start

Switch to the main branch, pull the latest changes with rebase, and delete the original branch.

Frequently Asked Questions about git-branch-cleanup

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

FAQPage Schema
How do I safely delete a git branch after merging a pull request?

Safely deleting a git branch after a merge involves switching to main, pulling upstream changes with a rebase, and conditionally removing the original branch only after confirming all commits are merged.

What happens if I have uncommitted changes when running a branch cleanup?

When uncommitted changes are detected during branch cleanup, the operation halts to prevent losing work. Safeguards are in place to stop the switch to main and report the error before any deletion occurs.

How do I pull latest changes with rebase when switching to the main branch?

Pulling latest changes with rebase when switching to main requires checking out the main branch and executing a rebase pull. This incorporates upstream changes while maintaining a clean, linear commit history.

Does branch cleanup work if my current git HEAD is detached?

Branch cleanup does not proceed if your git HEAD is detached. The workflow includes safeguards that detect a detached HEAD state and report an error to prevent unsafe branch deletion.

What's the best way to keep my local git repository clean from stale feature branches?

Keeping a local git repository clean from stale branches is best achieved by switching to main, rebasing on the latest upstream changes, and deleting the merged feature branch in an end-to-end workflow.

Can I delete a feature branch that still has unmerged commits?

You cannot delete a feature branch with unmerged commits using this cleanup workflow. It conditionally deletes the branch only after confirming it has been merged, ensuring unmerged work is preserved.