-
Notifications
You must be signed in to change notification settings - Fork 0
Reintroduce rm and clean subcommands (#34) #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -253,9 +253,57 @@ One entry per branch with upstream, ahead/behind, last commit date, clean/dirty, | |||||||||||||||||||||||
| and path (relative to the project root). Includes branches with no worktree, | ||||||||||||||||||||||||
| shown with path `(none)`. `--json` emits the same fields as an array. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ### `git trees rm <branch|path> [--apply]` | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Removes a worktree and deletes its branch. Accepts either a branch name or a worktree path. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| By default (without `--apply`), reports what would be removed without making any changes. Pass `--apply` to perform the removal. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Worktree directories are removed via `TREES_RM_CMD` if configured, or `git worktree remove`. Local branches are deleted using `git branch -d` (falling back to `git branch -D` if needed). | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| A path target must be a worktree git already knows about; `rm` refuses any other | ||||||||||||||||||||||||
| directory. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| > **`TREES_RM_CMD` removes git's safety net.** `git worktree remove` refuses a | ||||||||||||||||||||||||
| > worktree that has uncommitted changes or untracked files. A custom command such | ||||||||||||||||||||||||
| > as `rm -rf` receives only the path and makes no such check, so `rm --apply` and | ||||||||||||||||||||||||
| > `clean --apply` will destroy uncommitted work without warning. Set it only if | ||||||||||||||||||||||||
| > you want `git worktree remove --force` semantics deliberately. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ### `git trees clean [--merged|--gone] [--apply]` | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Reports or removes stale worktrees and branches. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Selectors: | ||||||||||||||||||||||||
| - `--gone`: branches whose upstream remote branch was deleted (`[gone]`) | ||||||||||||||||||||||||
| - `--merged`: branches merged into the default branch. Automatically detects direct merges, rebased/cherry-picked commits, and squash-merged PRs while leaving fresh 0-commit branches intact. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Passing neither selector runs both `--gone` and `--merged`. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| By default (without `--apply`), `clean` operates in dry-run mode and prints matching branches/worktrees without deleting them. Pass `--apply` to execute removals. Worktree directories are removed via `TREES_RM_CMD` if set (defaulting to `git worktree remove`) — see the warning above — and branches are deleted using `git branch -d` (falling back to `git branch -D` for gone/squash-merged branches). | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| `clean --apply` keeps going when an individual removal fails, reporting each one | ||||||||||||||||||||||||
| on stderr, and exits nonzero if any of them did. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ## Removing worktrees | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| `git-trees` does not delete anything. Remove a worktree and its branch with git: | ||||||||||||||||||||||||
| `git-trees` provides `rm` and `clean` for removing worktrees and branches: | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||
| git trees rm feature-x --apply # remove a single worktree and its branch | ||||||||||||||||||||||||
| git trees clean --apply # remove merged and gone branches/worktrees | ||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Both subcommands default to dry-run mode (report only) unless `--apply` is passed. | ||||||||||||||||||||||||
| Both also delete unmerged work once `--apply` is given — `-d` escalates to `-D`. | ||||||||||||||||||||||||
| If you have set `TREES_RM_CMD`, read the warning under [`git trees | ||||||||||||||||||||||||
| rm`](#git-trees-rm-branchpath---apply) first: it removes git's check for | ||||||||||||||||||||||||
| uncommitted changes. | ||||||||||||||||||||||||
|
Comment on lines
+300
to
+304
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win Specify “unmerged branches,” not “unmerged work.” The phrase can be confused with uncommitted changes. The following warning concerns uncommitted changes, while Proposed wording-Both also delete unmerged work once `--apply` is given — `-d` escalates to `-D`.
+Both can delete unmerged branches once `--apply` is given — branch deletion starts
+with `git branch -d` and escalates to `git branch -D`.📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Alternatively, you can use plain git: | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||
| git worktree remove <path> | ||||||||||||||||||||||||
|
|
@@ -271,6 +319,7 @@ git worktree prune | |||||||||||||||||||||||
| | `TREES_ORG` | *(unset)* | Default org; if unset, bare repo names are rejected | | ||||||||||||||||||||||||
| | `TREES_AGENTS_TEMPLATE` | `~/.config/git-trees/AGENTS.md` | Seeded at the container root by `init` (and `root --agents`) | | ||||||||||||||||||||||||
| | `TREES_NO_PUSH` | *(unset)* | Any non-empty value: `add`/`track` never create a branch on `origin` | | ||||||||||||||||||||||||
| | `TREES_RM_CMD` | *(unset)* | Custom command for worktree directory removal (defaults to `git worktree remove`). Bypasses git's uncommitted-work check — see [`git trees rm`](#git-trees-rm-branchpath---apply) | | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ## Shell wrapper (optional) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
@@ -288,8 +337,8 @@ trees() { | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ## Known limitations | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| - Removing stale worktrees and branches is manual; nothing here deletes. | ||||||||||||||||||||||||
| - `list` spawns several processes per branch — fine for dozens, slow for hundreds. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| - `add` ignores `base` when the branch already exists rather than failing. | ||||||||||||||||||||||||
| - Branch names beginning with `-` are unsupported: `add` parses them as options | ||||||||||||||||||||||||
| and reports `unknown option`. There is no `--` end-of-options marker. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.