Skip to content

Improve worktree removal error message by surfacing Git’s reason #54

@chhoumann

Description

@chhoumann

Hi! I’m using git gtr rm and noticed that when git worktree remove fails (e.g., index changes, untracked files), the CLI only prints a generic error:

Actual: [x] Failed to remove worktree
Expected: include Git’s reason (e.g., “contains modified or untracked files, use --force”).

Repro:

  1. Create a worktree: git gtr new test-remove-reason --no-fetch --no-copy
  2. In that worktree, make a staged change: echo "x" >> README.md && git add README.md
  3. Attempt removal: git gtr rm test-remove-reason

Proposed fix:
Capture git worktree remove stderr/stdout and include it in the error message.

Patch:

diff --git a/lib/core.sh b/lib/core.sh
index 9a1a1d1..c2f0b58 100644
--- a/lib/core.sh
+++ b/lib/core.sh
@@ -423,11 +423,16 @@ remove_worktree() {
-  if git worktree remove $force_flag "$worktree_path" 2>/dev/null; then
+  local remove_output
+  if remove_output=$(git worktree remove $force_flag "$worktree_path" 2>&1); then
     log_info "Worktree removed: $worktree_path"
     return 0
   else
-    log_error "Failed to remove worktree"
+    if [ -n "$remove_output" ]; then
+      log_error "Failed to remove worktree: $remove_output"
+    else
+      log_error "Failed to remove worktree"
+    fi
     return 1
   fi
 }

Environment:

  • OS: macOS 26.1
  • Git version: 2.52.0
  • Shell: zsh

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions