Dlt create-worktree
Create or reuse a git worktree for a pull request or branch so reviews and work happen in isolation
install
source · Clone the upstream repo
git clone https://github.com/dlt-hub/dlt
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/dlt-hub/dlt "$T" && mkdir -p ~/.claude/skills && cp -r "$T/.claude/skills/create-worktree" ~/.claude/skills/dlt-hub-dlt-create-worktree && rm -rf "$T"
manifest:
.claude/skills/create-worktree/SKILL.mdsource content
Git Worktree
Set up an isolated git worktree.
Parse
$ARGUMENTS to extract:
- The worktree name (required) — used as the directory name under
.worktrees/
(optional) — checkout a GitHub PR into the worktree using--pr <number>gh pr checkout
(optional) — create the worktree from a specific branch or ref--branch <ref>
Steps
1. Determine worktree path
The worktree path is:
<repo-root>/.worktrees/<name>
For example, if the repo root is
/home/user/src/dlt and the name is review-pr-3584, the worktree path is /home/user/src/dlt/.worktrees/review-pr-3584.
Create the
.worktrees directory if it does not exist:
mkdir -p <repo-root>/.worktrees
2. Create or reuse the worktree
Check if a worktree already exists at that path:
git worktree list
- If a worktree already exists at the target path, reuse it.
- If
was given, run--pr
to make sure it is up to date.cd <worktree-path> && gh pr checkout <number> - If
was given, run--branch
.git -C <worktree-path> checkout <ref>
- If
- If no worktree exists at the target path, create one:
- If
was given, first resolve the PR's branch name:--prgh pr view <number> --json headRefName -q .headRefName - If
or--pr
was given, check--branch
output for any other worktree that already has the same branch checked out. If found:git worktree list- Use
to ask the user: "BranchAskUserQuestion
is already checked out in worktree<branch>
. Use that worktree instead?"<existing-path> - If the user says yes, use the existing worktree path (skip creation, proceed to step 3 with the existing path).
- If the user says no, STOP — do not create a new worktree. Print a message explaining that the branch is already checked out elsewhere and exit.
- Use
- If no conflict, create the worktree:
- If
was given:--branchgit worktree add .worktrees/<name> <ref> - Otherwise:
git worktree add .worktrees/<name> --detach - If
was given, then also:--prcd <worktree-path> && gh pr checkout <number>
- If
- If
handles fetching, fork tracking, and branch setup automatically.gh pr checkout
3. Switch cwd
cd <worktree-path>
Then verify the switch took effect:
pwd
If
pwd does not show the worktree path, stop with an error — the cwd did not persist.
4. Report
Worktree ready: <worktree-path>