worktrunk icon indicating copy to clipboard operation
worktrunk copied to clipboard

Feature: checkout command

Open curtbushko opened this issue 9 months ago • 5 comments

Hello,

I know that wt is more focused on local AI worktree usage but it could become the tool to use for working with worktrees.

My request is for a wt checkout command that:

  1. pops up a fzf style dialog with the remote branches
  2. when selected, checks out the remove branch

The major gotcha to this command is when people use / in their branch names, eg max/feature-foo, the git reference does not like /. git will add a reference under .bare/worktrees for the worktree.

Your final tree should look like (notice .bare/worktrees/max-feature-foo):

 .
├──  .bare
│   └──  worktrees
│       └──  max-feature-foo   <---- converted '/' to '-'
├──  main
└──  max
    └──  feature-foo

instead of:

 .
├──  .bare
│   └──  worktrees
│       └──  max
│           └──  feature-foo <--- this will fail all git commands
├──  main
└──  max
    └──  feature-foo

curtbushko avatar Mar 04 '26 15:03 curtbushko

Thanks for the suggestion! This is a feature request rather than a bug, so I'll leave it for a maintainer to evaluate and prioritize.

worktrunk-bot avatar Mar 04 '26 15:03 worktrunk-bot

does wt switch --remotes do this?

max-sixty avatar Mar 04 '26 16:03 max-sixty

Thanks for pointing that out and it should work but it does not.

Would you like a new bug report on what I am seeing?

Steps:

  1. wt switch --remotes
  2. interactive with all origin branches shows up
  3. select branch named origin/username/feature-1
  4. No branch named origin/username/feature-1

Branch definitely exists and main is updated with latest references.

curtbushko avatar Mar 04 '26 22:03 curtbushko

ah, that is not good; I think that is indeed a bug, apologies.

@worktrunk-bot could you please triage?

max-sixty avatar Mar 05 '26 00:03 max-sixty

Triaged and fixed in #1266.

Root cause: When the interactive picker returns a remote branch name like origin/username/feature-1, it's passed directly to resolve_switch_target. The code then looks for refs/heads/origin/username/feature-1 (local) and refs/remotes/*/origin/username/feature-1 (remote pattern) — both wrong patterns that never match.

Fix: Before resolving the branch, detect remote-tracking ref names via git rev-parse --verify refs/remotes/<name> and strip the remote prefix (e.g., origin/) so DWIM can create a local tracking branch normally. This handles branch names with / correctly by matching against the configured remote names.

The same fix also works for wt switch origin/feature from the CLI, not just the picker.

worktrunk-bot avatar Mar 05 '26 01:03 worktrunk-bot