Skip to content

worktree create should check out existing local branches #729

Description

@Fryuni

Is this a reproducible bug?

  • I confirm this is a reproducible bug, not a feature request, idea, question, contribution proposal, or direction check.

Current behavior

herdr worktree create --branch NAME always tries to create NAME as a new branch. If NAME already exists locally, Herdr runs the equivalent of git worktree add -b NAME <checkout> <base>, and Git fails with fatal: a branch named 'NAME' already exists.

This affects both the CLI/socket worktree.create path and the New worktree keybinding/dialog. Related: #657 covered the stuck/error-display path; this report is specifically about allowing existing local branches.

Expected behavior

If NAME already exists as a local branch and is not checked out by another worktree, Herdr should create the checkout with git worktree add <checkout> NAME. If NAME does not exist, keep the current new-branch behavior from --base or HEAD. If the branch is already checked out elsewhere, surface Git's error or guide the user to worktree open.

Reproduction

  1. In a repo with one commit, create a branch: git branch existing-branch.
  2. Run herdr worktree create --cwd /path/to/repo --branch existing-branch --json, or use the New worktree keybinding and enter existing-branch.
  3. Herdr attempts to create the already-existing branch instead of checking it out, so worktree creation fails.

Impact

This makes Herdr worktree creation awkward for the common flow where a branch already exists from previous work or after removing an old checkout. Users have to drop to raw git worktree add <path> <branch> or use a separate open-existing flow instead of the create command/dialog doing the expected thing.

Environment

  • Herdr version: current upstream master behavior; also consistent with the 0.7.0 worktree-create command shape
  • Update channel (stable or preview): source build / not channel-specific
  • Operating system: Linux/NixOS; behavior comes from Git command construction and should be platform-independent
  • Terminal: not terminal-specific
  • Shell, if relevant: not shell-specific
  • Relevant config, if any: worktree creation with default or configured [worktrees].directory

Filed by Hermes Agent by Nous Research at user request. No PR is being opened; we will maintain this in a downstream fork since PRs to upstream require approval from maintainers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions