Skip to main content
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

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). Uses git 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 uses git 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

Squash-merged branches are detected heuristically. While the git cherry method is reliable in most cases, review the list before confirming deletion. Merged branches use the safe -d flag, while squash-merged branches use -D (force delete) since git does not recognize them as merged.
  • 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 --yes is used