@@ -43,6 +43,40 @@ Examples:
4343EOF
4444}
4545
46+ _help_pr () {
47+ cat << 'EOF '
48+ git gtr pr - Create a worktree for a GitHub pull request
49+
50+ Usage: git gtr pr <number|url|branch> [options]
51+
52+ Creates a worktree from a GitHub pull request, similar to gh pr checkout.
53+ Uses gh's native worktree checkout when available and a compatible fallback
54+ otherwise, preserving configured Git remotes and protocols.
55+ The default local branch is the PR head branch so GitHub CLI can infer the PR
56+ from inside the worktree. Requires GitHub CLI (gh) for PR lookup.
57+
58+ Options:
59+ -b, --branch <name> Local branch name to use (default: PR head branch)
60+ -R, --repo <repo> Select GitHub repository for gh pr view
61+ --remote <name> Override remote/repository used to fetch refs/pull/<number>/head
62+ --no-copy Skip file copying (gtr.copy.include patterns)
63+ --no-hooks Skip post-create hooks
64+ --force Allow same branch in multiple worktrees
65+ (requires --name or --folder to distinguish worktrees)
66+ --name <suffix> Custom folder name suffix (appended after branch name)
67+ --folder <name> Custom folder name (replaces default entirely)
68+ --yes Non-interactive mode (skip prompts)
69+ -e, --editor Open in editor after creation
70+ -a, --ai Start AI tool after creation
71+
72+ Examples:
73+ git gtr pr 123 # Branch/folder from PR head branch
74+ git gtr pr 123 --branch review/fix # Custom local branch
75+ git gtr pr https://github.com/OWNER/REPO/pull/123 --folder review
76+ gtr pr 123 --cd # With shell integration
77+ EOF
78+ }
79+
4680_help_editor () {
4781 cat << 'EOF '
4882git gtr editor - Open worktree in editor
@@ -369,8 +403,9 @@ git gtr init - Generate shell integration
369403
370404Usage: git gtr init <shell> [--as <name>]
371405
372- Generates shell functions for enhanced features like 'gtr cd <branch>'
373- and 'gtr new <branch> --cd', which can change the current shell directory.
406+ Generates shell functions for enhanced features like 'gtr cd <branch>',
407+ 'gtr new <branch> --cd', and 'gtr pr <number> --cd', which can change the
408+ current shell directory.
374409Add to your shell configuration.
375410
376411Output is cached to ~/.cache/gtr/ for fast shell startup (~1ms vs ~60ms).
@@ -387,24 +422,25 @@ Options:
387422Setup (sources cached output directly for fast startup):
388423 # Bash (add to ~/.bashrc)
389424 _gtr_init="${XDG_CACHE_HOME:-$HOME/.cache}/gtr/init-gtr.bash"
390- [[ -f "$_gtr_init" ]] || eval "$(git gtr init bash)" || true
425+ [[ -f "$_gtr_init" ]] && head -n 1 "$_gtr_init" | grep -q ' init=6 ' || eval "$(git gtr init bash)" || true
391426 source "$_gtr_init" 2>/dev/null || true; unset _gtr_init
392427
393428 # Zsh (add to ~/.zshrc)
394429 _gtr_init="${XDG_CACHE_HOME:-$HOME/.cache}/gtr/init-gtr.zsh"
395- [[ -f "$_gtr_init" ]] || eval "$(git gtr init zsh)" || true
430+ [[ -f "$_gtr_init" ]] && head -n 1 "$_gtr_init" | grep -q ' init=6 ' || eval "$(git gtr init zsh)" || true
396431 source "$_gtr_init" 2>/dev/null || true; unset _gtr_init
397432
398433 # Fish (add to ~/.config/fish/config.fish)
399434 set -l _gtr_init (test -n "$XDG_CACHE_HOME" && echo $XDG_CACHE_HOME || echo $HOME/.cache)/gtr/init-gtr.fish
400- test -f "$_gtr_init"; or git gtr init fish >/dev/null 2>&1
435+ test -f "$_gtr_init"; and head -n 1 "$_gtr_init" | string match -q '* init=6 *'; or git gtr init fish >/dev/null 2>&1
401436 source "$_gtr_init" 2>/dev/null
402437
403438 # Custom function name (avoids conflict with coreutils gtr)
404439 eval "$(git gtr init zsh --as gwtr)"
405440
406441After setup:
407442 gtr new my-feature --cd # create and cd into worktree
443+ gtr pr 123 --cd # create PR worktree and cd
408444 gtr cd my-feature # cd to worktree
409445 gtr cd 1 # cd to main repo
410446 gtr cd # interactive picker (requires fzf)
@@ -528,6 +564,20 @@ CORE COMMANDS (daily workflow):
528564 -e, --editor: open in editor after creation
529565 -a, --ai: start AI tool after creation
530566
567+ pr <number|url|branch> [options]
568+ Create a worktree from a GitHub pull request (requires gh)
569+ -b, --branch <name>: local branch name (default: PR head branch)
570+ -R, --repo <repo>: repository for gh pr view
571+ --remote <name>: override remote/repository used to fetch refs/pull/<number>/head
572+ --no-copy: skip file copying
573+ --no-hooks: skip post-create hooks
574+ --force: allow same branch in multiple worktrees (requires --name or --folder)
575+ --name <suffix>: custom folder name suffix
576+ --folder <name>: custom folder name
577+ --yes: non-interactive mode
578+ -e, --editor: open in editor after creation
579+ -a, --ai: start AI tool after creation
580+
531581 editor <branch> [--editor <name>]
532582 Open worktree in editor (uses gtr.editor.default or --editor)
533583 Special: use '1' to open repo root
@@ -628,7 +678,7 @@ SETUP & MAINTENANCE:
628678 Usage: eval "$(git gtr completion zsh)"
629679
630680 init <shell> [--as <name>]
631- Generate shell integration for gtr cd and gtr new --cd (bash, zsh, fish)
681+ Generate shell integration for gtr cd, gtr new --cd, and gtr pr --cd (bash, zsh, fish)
632682 --as <name>: custom function name (default: gtr)
633683 Output is cached for fast startup (refreshes when 'git gtr init' runs)
634684 See git gtr help init for recommended setup
@@ -648,6 +698,7 @@ WORKFLOW EXAMPLES:
648698
649699 # Daily workflow
650700 git gtr new feature/user-auth # Create worktree (folder: feature-user-auth)
701+ git gtr pr 123 # Create worktree for pull request #123
651702 git gtr editor feature/user-auth # Open in editor
652703 git gtr ai feature/user-auth # Start AI tool
653704
@@ -657,6 +708,7 @@ WORKFLOW EXAMPLES:
657708
658709 # Navigate to worktree directory
659710 gtr new hotfix --cd # Create and cd into worktree (with shell integration)
711+ gtr pr 123 --cd # Create PR worktree and cd
660712 gtr cd # Interactive picker (requires fzf)
661713 gtr cd feature/user-auth # With shell integration (git gtr init)
662714 cd "$(git gtr go feature/user-auth)" # Without shell integration
@@ -709,7 +761,7 @@ CONFIGURATION OPTIONS:
709761 gtr.hook.postCreate Post-create hooks (multi-valued)
710762 gtr.hook.preRemove Pre-remove hooks (multi-valued, abort on failure)
711763 gtr.hook.postRemove Post-remove hooks (multi-valued)
712- gtr.hook.postCd Post-cd hooks (multi-valued, gtr cd / gtr new --cd only)
764+ gtr.hook.postCd Post-cd hooks (multi-valued, gtr cd / gtr new --cd / gtr pr --cd only)
713765 gtr.ui.color Color output mode (auto, always, never; default: auto)
714766
715767────────────────────────────────────────────────────────────────────────────────
0 commit comments