Create a worktree and branch from just a path

basics

// what it does

With no branch argument, git worktree add derives everything from the path: it takes the basename (hotfix), creates that branch from your current HEAD if it doesn't exist, and checks it out at ../hotfix. One argument — new branch, new directory.

// shell

$ git worktree add ../hotfix

// gotcha

If a branch named after the basename already exists, git checks out that existing branch instead of creating a fresh one — you might silently resume months-old work. And the branch name comes from the last path component only: ../wt/payment-fix names the branch payment-fix, not wt/payment-fix.

// resources