Git Worktrees
Resolve this skill's directory, then invoke its bundled scripts/worktree.sh. Pass -C <repo> when the shell is not already inside the target repository.
Add
<skill-directory>/scripts/worktree.sh -C <repo> add <branch> [start-point]
The script:
- uses an existing local branch when present;
- creates a tracking branch when
<remote>/<branch>exists; - otherwise creates the branch from
start-point, the remote default branch, orHEAD; - prints the created worktree path.
Fetch the remote before adding when the worktree must start from its latest state:
git -C <repo> fetch origin
<skill-directory>/scripts/worktree.sh -C <repo> add feat/example origin/main
Worktrees default to <repo>__worktrees/<branch-with-slashes-as-dashes>. Set WORKTREE_ROOT to use another parent and WORKTREE_REMOTE to use a remote other than origin.
Remove
<skill-directory>/scripts/worktree.sh -C <repo> remove <branch-or-path>
<skill-directory>/scripts/worktree.sh -C <repo> remove --force <branch-or-path>
Normal removal preserves Git's dirty-worktree protection. Use --force only when discarding the worktree's uncommitted files is intended. Removal unregisters and deletes the worktree directory; it leaves the branch intact.
An add is complete when the script prints the new path and git -C <repo> worktree list contains it. A removal is complete when that path is absent.