From 2b81c4bcd98070f35d37525b45cf9cdf93d61824 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Thu, 5 Mar 2026 11:19:16 +0000 Subject: [PATCH] Create new branch for worktree if it doesn't exist --- worktree/worktree.plugin.zsh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/worktree/worktree.plugin.zsh b/worktree/worktree.plugin.zsh index bc8701f..6731cd0 100644 --- a/worktree/worktree.plugin.zsh +++ b/worktree/worktree.plugin.zsh @@ -33,7 +33,11 @@ Manage git worktrees by branch name." add) local root=$(git rev-parse --show-toplevel) local wt_dest=${root:h}/${root:t}@${branch} - git worktree add "$wt_dest" "$branch" + if ! git show-ref --verify --quiet refs/heads/"$branch" && \ + ! git show-ref --verify --quiet refs/remotes/origin/"$branch"; then + git branch "$branch" origin/main || return 1 + fi + git worktree add "$wt_dest" "$branch" || return 1 if [ -f $root/.enter ] && [ -f $root/.exit ]; then ln -s $root/.enter $wt_dest/.enter ln -s $root/.exit $wt_dest/.exit