Create Git Worktree
Create a new git worktree with a branch that's based off the current branch.
Arguments
- •
$ARGUMENTSshould contain:- •branch-name (required): Name for the new branch
- •worktree-path (optional): Path for the worktree directory. Defaults to
.worktrees/<branch-name>
Steps
- •Get the current branch name using
git branch --show-current - •Get the repo root using
git rev-parse --show-toplevel - •Parse the arguments from
$ARGUMENTS:- •First argument is the branch name
- •Second argument (if provided) is the worktree path, otherwise use
<repo-root>/.worktrees/<branch-name>
- •Ensure
.worktreesdirectory exists - •Create the worktree with a new branch based on the current branch:
bash
git worktree add -b <new-branch> <worktree-path>
- •Report the created worktree location and the base branch
Example Usage
code
/worktree feature-auth # Creates worktree at .worktrees/feature-auth with branch feature-auth based on current branch /worktree feature-auth ~/projects/myrepo-auth # Creates worktree at ~/projects/myrepo-auth with branch feature-auth
Output
After creating the worktree, display:
- •The new branch name
- •The base branch it was created from
- •The worktree path