About soft-delete-git
soft-delete-git is a skill for safely deleting the currently checked-out Git branch. It checks the working tree, updates the default branch, and restricts force deletion to a confirmed squash-merged pull request.
Key features
- 01Checks for uncommitted changes
- 02Identifies the current and default branches
- 03Updates the default branch before deletion
- 04Uses safe branch deletion by default
- 05Verifies squash-merged pull requests before force deletion
Use cases
- 01Remove a completed feature branch safely
- 02Pause for user guidance when the working tree is dirty
- 03Handle branches merged through GitHub squash merge
Install
Copy the command and run it in a terminal.
npx skills add https:/ / github.com/ rubenflamshepherd/ ruben-agent-skills --skill soft-delete-gitAfter installing, type/soft-delete-gitin Claude Code to confirm it loaded.
Details
From the project READMESoft Delete Git Branch Workflow
Invocation behavior
When this skill is invoked without an explicit branch name, target the currently checked-out branch. Invocation of the skill is authorization to begin the workflow immediately: inspect the working tree and determine the current branch without asking which branch to delete.
Only ask the user how to proceed when:
- The working tree is dirty.
- The current branch is the default branch.
- Safe deletion fails and force deletion would require confirmation.
Do not ask the user to name or confirm the current branch before starting.
Steps:
-
Check for uncommitted changes
git status --porcelainIf the working tree is dirty, stop and ask the user how to proceed (commit, stash, or discard) before switching branches.
-
Get current branch name
git branch --show-currentIf already on the default branch, there is no branch to delete — stop and ask the user which branch they meant.
-
Determine the default branch
git symbolic-ref --short refs/remotes/origin/HEADThis returns e.g.
origin/main— the default branch is the part afterorigin/. If the ref is unset, fall back tomain. -
Check out the default branch
git checkout <default-branch> -
Pull latest changes
git pull -
Soft delete the previous branch
git branch -d <branch-name> -
If soft delete fails, check for a squash merge
git branch -dfails for branches merged via GitHub's "Squash and merge", because the branch tip is never an ancestor of the default branch. Check whether the branch's PR was actually merged:gh pr view <branch-name> --json state,mergedAt- If the PR state is
MERGED, confirm with the user, then delete withgit branch -D <branch-name>. - Otherwise, escalate to the user rather than force-deleting.
- If the PR state is
Notes:
- Uses lowercase
-dfor soft delete (safe delete that prevents deletion of unmerged branches) - Never use uppercase
-D(hard delete) except in the verified-squash-merge case above, and only after confirming with the user - The workflow ensures the default branch is up to date before attempting the delete