Git Worktrees for Pull Requests (git-wtpr)
Use git wtpr to create or switch to a worktree checked out at a PR head.
Builds on git-wt — prefer this over gh pr checkout when isolation in a
worktree is needed.
Usage
git wtpr <number|url> [git-wt flags...]
git wtpr <number|url> -d | -D
Examples:
git wtpr 25
git wtpr https://github.com/owner/repo/pull/3984
git wtpr 25 -D # remove that PR worktree
Interactive use (with git-wtpr --init fish) cds into the worktree,
same as git wt. Do not pass --nocd unless you only need the path.
Confirm availability with command -v git-wtpr or git-wtpr --help.
Behaviour
- Resolves the PR with
gh pr view(number or URL). - Ensures the current clone matches the PR repository.
- Fetches
pull/<n>/headfrom the remote. - Creates or switches a worktree via
git wton the PR head branch name. - If the head branch is
main/master, usespr-<number>instead. - Shell integration cds into that worktree (unless
--nocd/wt.nocd).
Status goes to stderr. The worktree path is the last stdout line.
With -d (safe) or -D (force) the PR worktree and its branch are
deleted instead — the PR is still resolved to get the branch name, but
step 3 is skipped.
Workflow for agents
- Run from the correct repository clone (not a random directory).
- Use
git wtpr --nocd <pr>— shellcddoes not persist across tool calls, so capture the printed path and use it as the working directory. - Verify inside the worktree:
git branch --show-currentandgit status --short. - To clean up afterwards, run
git wtpr <pr> -Dfrom the same clone (orgit wt -D <branch>). For other lifecycle operations (list, rename), use thegit-wtskill.
Related
git-wtskill for worktree create/switch/delete/renameagents/shared/git-worktrees.mdfor when not to create a new worktree