Open a git worktree in VS Code or any editor
Configure your editor command once:
worktree config codeEditor codeThen open any worktree quickly:
worktree open feature/add-bulk-actionsIf omitted, worktree open will show an interactive branch picker.
Similarly, if omitted, worktree checkout will show an interactive remote branch picker.
The codeEditor value
Section titled “The codeEditor value”Set it to the executable plus any arguments it needs. The worktree path is appended as the final argument:
worktree config codeEditor code # code <path>worktree config codeEditor "code -n" # code -n <path>worktree config codeEditor "subl -w" # subl -w <path>The value is split on whitespace, and quotes group — so an argument containing a space survives:
worktree config codeEditor 'open -a "Sublime Text"'No shell is involved. The executable is run directly with those arguments, which is what lets a
worktree path containing a space open correctly. It also means nothing is expanded: ~ and
$EDITOR are passed through literally rather than resolved, and a backslash is an ordinary
character rather than an escape — quote an argument like this instead of writing
an\ argument\ like\ this. Use an absolute path, or a wrapper script on your PATH, instead of
relying on expansion.
Quote characters group wherever they appear, as a shell’s do, with one exception: an apostrophe
between two letters or digits, such as the one in /Users/o'brien/bin/ed, is an ordinary
character and stays in the value. Your own shell still parses what you type, so wrap the value in
double quotes (or single quotes with the apostrophe spelled '"'"') to get it to worktree intact:
worktree config codeEditor "/Users/o'brien/bin/ed"worktree config codeEditor "/Users/o'brien/bin/ed --wait"An apostrophe anywhere else, such as at the start or end of a word, still opens a quote.
Opening somewhere other than an editor
Section titled “Opening somewhere other than an editor”Set opener to herdr to have worktrees land as Herdr spaces instead, or to rex for Rex sessions. Set it
to auto to open in whichever of the two the command runs inside, with codeEditor as the fallback when it
is in neither. See Herdr Spaces and
Rex Sessions.
Platform support
Section titled “Platform support”worktree is developed and tested on macOS and Linux. Windows is not supported: the editor is
launched without a shell, so a PATHEXT wrapper such as code.cmd is not resolved.