Skip to main content

Cleaning Branches

Cleaning Branches

Destructive Maintenance

Select branches through explicit prefix, merge-state, and optional age filters before permanent Git deletion.

Commandcusty cleanup branches

Category

User Guide

Quick Command

custy --dry-run cleanup brancheses [OPTIONS]

local branchesremote branchespreview required

Goal

Use branch cleanup for deliberate repository maintenance after merged or stale work is no longer needed. The active CLI subcommand is plural: custy cleanup branches.


How a Branch Becomes Eligible

All Applicable Filters Must Pass

Protected Name

main, master, and develop are excluded by the active request defaults.

Configured Prefix

The branch must begin with one of the explicit prefixes. Empty prefixes select nothing.

Merge State

The branch must match merged, unmerged, or all according to resolved policy.

Optional Time Filter

Use either maximum age or an absolute before date, never both.

Recommended Cleanup Journey

Review Before Deletion

1
Fetch and inspect repository state
Refresh remote knowledge and review local and remote branches manually.
completed
2
Choose narrow prefixes
Select only known branch families such as feature/ or release/.
completed
3
Choose merge and time filters
Prefer merged branches and add one optional age boundary when useful.
completed
4
Dry-run the exact command
Review every candidate and skipped branch before normal execution.
current
5
Execute and verify
Run normally, then confirm local and remote branch lists.
pending
Narrow merged-branch cleanup
bash
git fetch --all --prune
git branch --all

custy --dry-run cleanup brancheses --prefix feature/ --merge-status merged --max-age 30d

On PowerShell, place the command on one line or use PowerShell's continuation syntax instead of the Bash backslashes shown above.



Before Normal Execution

Before You Begin

  • Candidates are listedRequired

    Every branch selected by dry-run is expected and recoverable if needed.

  • Protected work is pushedRequired

    Important commits exist in a safe branch, tag, or reviewed remote location.

  • Merge status is appropriateRequired

    Avoid unmerged or all unless their deletion is explicitly intended.

  • Only one time filter resolvesRequired

    max_age and before are mutually exclusive.

  • Remote deletion is acceptableRequired

    Confirm matching origin branches may be removed as well as local branches.

Execute and verify
bash
custy cleanup branches --prefix feature/ --merge-status merged --max-age 30d
git branch --all

If the Wrong Branch Was Deleted

Stop additional cleanup. If you know the branch's last commit SHA and the object is still available locally, recreate a local branch with standard Git recovery tools, review it, and push only if the remote branch also needs to be restored. If the commit is not known, inspect reflog and repository-host history before taking further action.

This recovery is intentionally manual because Custy does not maintain a branch deletion undo journal.


Continue