gx sweep scans your repo for cleanup opportunities and offers to delete merged branches, likely squash-merged branches, and stale remote tracking refs in one pass.
Usage
Flags
| Flag | Short | Description |
|---|---|---|
--dry-run | Show what would be cleaned without making changes | |
--yes | -y | Skip confirmation prompts |
Three Categories
gx sweep identifies three types of cleanup targets:1. Merged Branches (safe to delete)
Branches that are fully merged into the HEAD branch (main/master). Usesgit branch --merged.
2. Squash-Merged Branches
Branches where all commits are already present in the HEAD branch, even though they were not merged via a merge commit. This handles the common GitHub “Squash and merge” workflow. gx usesgit cherry to detect these: if every commit on the branch is prefixed with - (meaning an equivalent commit exists on the target), the branch is considered squash-merged.
3. Stale Remote Tracking Refs
Remote tracking references (origin/...) that point to branches that no longer exist on the remote. Detected via git remote prune origin --dry-run.
Example
Additional behavior
Additional behavior
- The current branch and HEAD branch are never included in cleanup candidates
- After deletion, gx also cleans stale entries from the stack config (
.git/gx/stack.json) - If nothing needs cleanup, gx prints
OK Nothing to clean up. Repository is tidy! - Each category is confirmed separately unless
--yesis used