It's currently hard to use the telescope worktree creation functionality, because it only works well for branches that have been checked out locally as well. There are a few issues when trying to create a worktree from a tracking branch:
The Git.has_branchlogic will not find the branch (the git branch list does not contain remote tracking branches) and hence a new branch will incorrectly be created here.
Fix: check for remote tracking branches as well
The following issue in git-worktree v1 still applies when one tries to create a git worktree from a remote-tracking branch: https://github.com/ThePrimeagen/git-worktree.nvim/issues/77. To summarize, for the new branch the <remote>/ prefix is kept in the local branch name as well, which results in a rather confusing user experience (e.g. in git log, there's now two references called <origin>/<branch>).
Potential fix (related PR: https://github.com/polarmutex/git-worktree.nvim/pull/20.): git checkout and git worktree add have the same semantics, where if the starting branch is a tracking branch that does not exist locally and is present in a single remote, then a local checkout is created. Therefore, the Telescope git_branches command has faced a similar concern already, where remote branches are shown but usually what the user wants is to checkout a new, local branch (relevant issue: https://github.com/nvim-telescope/telescope.nvim/issues/1932). They have solved this by binding the function git_track_branch (https://github.com/nvim-telescope/telescope.nvim/blob/5972437de807c3bc101565175da66a1aa4f8707a/lua/telescope/actions/init.lua#L748-L756) to \<C-T>, allowing one to pass the --track option to git checkout, which provides the correct semantics. The telescope picker for git-worktree could similarly allow passing the --track option to git worktree add.
It's currently hard to use the telescope worktree creation functionality, because it only works well for branches that have been checked out locally as well. There are a few issues when trying to create a worktree from a tracking branch:
Git.has_branch
logic will not find the branch (thegit branch
list does not contain remote tracking branches) and hence a new branch will incorrectly be created here. Fix: check for remote tracking branches as wellgit-worktree v1
still applies when one tries to create a git worktree from a remote-tracking branch: https://github.com/ThePrimeagen/git-worktree.nvim/issues/77. To summarize, for the new branch the<remote>/
prefix is kept in the local branch name as well, which results in a rather confusing user experience (e.g. ingit log
, there's now two references called<origin>/<branch>
). Potential fix (related PR: https://github.com/polarmutex/git-worktree.nvim/pull/20.):git checkout
andgit worktree add
have the same semantics, where if the starting branch is a tracking branch that does not exist locally and is present in a single remote, then a local checkout is created. Therefore, theTelescope git_branches
command has faced a similar concern already, where remote branches are shown but usually what the user wants is to checkout a new, local branch (relevant issue: https://github.com/nvim-telescope/telescope.nvim/issues/1932). They have solved this by binding the functiongit_track_branch
(https://github.com/nvim-telescope/telescope.nvim/blob/5972437de807c3bc101565175da66a1aa4f8707a/lua/telescope/actions/init.lua#L748-L756) to \<C-T>, allowing one to pass the--track
option togit checkout
, which provides the correct semantics. The telescope picker forgit-worktree
could similarly allow passing the--track
option togit worktree add
.git-worktree
semantics one would expect, and seems to cause the "double origin" part of the aforementioned issue (https://github.com/ThePrimeagen/git-worktree.nvim/issues/77).