A GitHub CLI extension for managing git worktrees for pull requests and branches. It checks out PRs and branches using git worktree, placing worktrees outside the current repository folder, and provides commands to list, remove, and cleanup worktrees.
../<repository-name>-<pr-number>
For example, if you're working in ~/projects/my-app and check out PR #42, the worktree will be created at ~/projects/my-app-42.
gh extension install <owner>/gh-worktreeFor local development:
gh extension install .# Check out a PR by number
gh worktree 42
gh worktree #42 # # prefix is optional
# Check out a branch
gh worktree my-feature-branch
# Explicit create command
gh worktree create 42# List all worktrees with PR information
gh worktree list
gh worktree ls # short aliasOutput shows path, branch, PR number, and state (OPEN/CLOSED/MERGED):
PATH BRANCH PR STATE
---- ------ -- -----
/Users/you/projects/my-app-42 feature-auth #42 OPEN
/Users/you/projects/my-app-99 bugfix-login #99 MERGED
/Users/you/projects/my-app-my-feature my-feature - -
# Remove by PR number
gh worktree remove 42
gh worktree rm #42 # short alias, # prefix optional
# Remove by directory name
gh worktree remove my-app-42
# Remove by absolute path
gh worktree remove /path/to/my-app-42
# Force removal (even with uncommitted changes)
gh worktree remove --force 42
gh worktree rm -f 42# Remove all worktrees for closed and merged PRs
gh worktree cleanup
# Preview what would be removed (dry run)
gh worktree cleanup --dry-run
gh worktree cleanup -n
# Only remove merged PRs (not closed)
gh worktree cleanup --merged-only
# Interactive mode (prompt before each removal)
gh worktree cleanup --interactive
gh worktree cleanup -i
# Combine options
gh worktree cleanup --dry-run --merged-onlyAfter the worktree is created, the following steps run automatically if applicable:
- yarn install: if a
yarn.lockfile is present in the new worktree, dependencies are installed automatically. - .vscode copy: if a
.vscodefolder exists in the main repository, it is copied into the new worktree so editor settings and launch configurations carry over.
When given a PR number, the create command:
- Resolves the PR's head branch via
gh pr view - Fetches via
refs/pull/<number>/head— works with fork PRs too - Creates the worktree at
../<repo>-<pr-number>
When given a branch name, the create command:
- Tries to find an associated open PR (to use its number in the directory name)
- Falls back to
../<repo>-<branch-name>if no PR is found
- List: Shows all worktrees with their associated PR status by fetching PR state from GitHub
- Remove: Deletes a worktree by PR number, directory name, or path
- Cleanup: Automatically identifies and removes worktrees for PRs that have been closed or merged
- gh — GitHub CLI
gitwith worktree support (git 2.5+)
| Command | Description |
|---|---|
gh worktree [create] <pr|branch> |
Create a new worktree (default command) |
gh worktree list |
List all worktrees with PR status |
gh worktree remove <identifier> |
Remove a worktree |
gh worktree cleanup |
Remove worktrees for closed/merged PRs |
- If the worktree directory already exists, the create command reports the path and exits — no overwriting.
- Running
cdinto the worktree must be done manually after the command prints the path (shell subprocesses cannot change the parent shell's directory). - The cleanup command can automatically remove worktrees for PRs that have been closed or merged, helping keep your workspace tidy.
- Use
--dry-runwith cleanup to preview what would be removed before actually deleting anything.