Skip to content

WORKTREE_PATH polluted when auto-creating remote-only branch (track_mode=auto) #32

@ueryooo

Description

@ueryooo

Summary

When creating a worktree in track_mode=auto for a branch that exists only on origin, stdout from git branch --track is mixed into create_worktree output. The returned WORKTREE_PATH becomes contaminated (e.g., starts with Branch 'foo' set up to track 'origin/foo'.), causing postCreate hooks to cd into the wrong path and fail.

Steps to Reproduce

  1. Ensure branch exists on origin only: git ls-remote --heads origin <branch> (no local branch).
  2. Run git gtr new <branch> (default track_mode=auto).
  3. Inspect WORKTREE_PATH passed to postCreate hook or echo the function output.

Expected Behavior

create_worktree stdout contains only the worktree path; WORKTREE_PATH is a clean path and cd "$WORKTREE_PATH" succeeds.

Actual Behavior

git branch --track prints to stdout, which is concatenated with the path. postCreate hook receives a polluted value and cd $WORKTREE_PATH fails (interpreted as cd Branch etc.).

Environment

  • Observed on: macOS (git 2.x, zsh)
  • Affects: track_mode=auto with remote-only branches; local/none modes and existing local branches are not affected.

Proposed Fix

Redirect git branch --track "$branch" "origin/$branch" stdout (and stderr) to /dev/null in the auto branch creation path, keeping create_worktree stdout clean. A one-line change in lib/core.sh resolves the issue.

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