You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
coreThis issue is not accepting PRs from outside contributorsenhancementa request to improve CLIgh-prrelating to the gh pr commandpitchpitched internally for prioritisation
Describe the feature or problem you’d like to solve
Make gh pr checkout support worktree to checkout the PR in a separate working directory without interrupting on-going work of current working directory.
Proposed solution
Maybe add a flag to gh pr checkout to instead checking out the branch inside the current worktree but create a new worktree with that PR checked out at a given location.
We can also add a config of the "directory of PR worktrees"? So the cli will create a new worktree inside the worktree directory <worktrees_dir>/pull/<pr-number>
Reacted by Kevin Roy, Bill Mill, Matthieu Harlé, Lily Ballard, Graham Davison, Joel Pettersson, GyuYong Jung, Brian Flad, Dirk Avery, Joel Palmer and 79 more
I'd like to see this, especially the "create a worktree in a known temporary location", but I would also want a way to say "prune all of my PR worktrees" so I can run that periodically.
If a directory is passed in, it could be the worktree directory.
% git statusOn branch mainYour branch is up to date with 'origin/main'.nothing to commit, working tree clean
% gh pr checkout 1492 ../worktree1
% cd ../worktree1
% git statusOn branch b-branch-associated-with-1492Your branch is up to date with 'upstream/b-branch-associated-with-1492'.nothing to commit, working tree clean
I wouldn't want this as the default for gh pr checkout but an option, maybe gh pr checkout --worktree perhaps with ../{{ current dir name}_pr{number} as a default but overridable argument to the switch.
I wrote a command for myself in my forked cli/cli. I went with gh pr worktree <branch>. Anyone at @github ok w/ that as a new command? I'd be happy to polish it, write some tests, and open PR. I dont think it makes sense to add worktree related stuf to the checkout command because they're completely separate in the world of git commands.
Reacted by Lily Ballard, Brian Flad, Matthieu Harlé, Nick Nisi, tobim, Hugo, George Pantazes, Ahmed Adan, Ahmed Adan, Julian Gernun and 8 more
For anyone else reading this who wants worktree support in GitHub CLI, just run this:
gh extension install despreston/gh-worktree
Thanks @despreston for writing and publishing this!
Reacted by Des Preston, Chuck Grindel, Devinda Senanayaka, Bharadwaj Srigiriraju, Casey Boettcher, Brandon Titus, Corentin Girard, Arya Irani, Mohamed Gaber, Michael Migdol and 3 more
Possibly due to the PR's source branch being in a forked repo. I'll post a ticket at despreston/gh-worktree, but I wanted to mention here that the problem's still not fully solved, and that a flag on the gh pr command would still be better.
I ended up somewhere similar. Instead of calling code though I just echo the path and then do as I desire from the call. I also store my worktrees within the repo itself and use a local gitignore to hide it. I've also resorted to just using branch name and using the "copy" button on the PR to see it.
Since this is still marked as core (outside contributors can't create pr's for changes marked core), and the team is not sure if they want to do this yet, I ended up creating an extension for this problem after trying the great options mentioned here.
I wanted something that could be used for more than just PR's. The main goal was to quickly spin up a worktree and spawn a Claude code instance in it with the initial prompt. I ended up creating an action concept to make it extensible passed just my use case.
@engnadeau use case for opening vscode after creation is a great example of how actions can be used.
gh wt add https://github.com/owner/repo/pull/123 -a vscode or gh wt run <worktree> <action> to execute actions in already existing worktrees.
coreThis issue is not accepting PRs from outside contributorsenhancementa request to improve CLIgh-prrelating to the gh pr commandpitchpitched internally for prioritisation
Activity
lilyball commentedon Oct 8, 2020
I'd like to see this, especially the "create a worktree in a known temporary location", but I would also want a way to say "prune all of my PR worktrees" so I can run that periodically.
YakDriver commentedon Apr 2, 2021
If a directory is passed in, it could be the worktree directory.
macintacos commentedon Apr 15, 2021
@YakDriver I keep getting a "too many arguments" error when trying that. Can you elaborate a bit on your setup?
In any case, as someone just discovering worktrees and how nice they are, I'm sad to see that this isn't already a thing with
gh.matschaffer commentedon Sep 10, 2021
I wouldn't want this as the default for
gh pr checkoutbut an option, maybegh pr checkout --worktreeperhaps with../{{ current dir name}_pr{number}as a default but overridable argument to the switch.despreston commentedon Jan 27, 2022
I wrote a command for myself in my forked cli/cli. I went with
gh pr worktree <branch>. Anyone at @github ok w/ that as a new command? I'd be happy to polish it, write some tests, and open PR. I dont think it makes sense to add worktree related stuf to the checkout command because they're completely separate in the world of git commands.cap10morgan commentedon Dec 22, 2022
@despreston I like your proposal (FWIW, I don't work at GitHub). You still thinking of opening a PR?
despreston commentedon Dec 22, 2022
@cap10morgan I ended up writing a plugin.
https://github.com/despreston/gh-worktree
cap10morgan commentedon Dec 22, 2022
Oh, cool. I didn't know those were a thing.
For anyone else reading this who wants worktree support in GitHub CLI, just run this:
gh extension install despreston/gh-worktreeThanks @despreston for writing and publishing this!
Checkout pr in new worktree
Checkout pr in new worktree
Checkout pr in new worktree
aryairani commentedon Oct 29, 2023
Thanks for writing this, but it doesn't work for me though:
Possibly due to the PR's source branch being in a forked repo. I'll post a ticket at despreston/gh-worktree, but I wanted to mention here that the problem's still not fully solved, and that a flag on the
gh prcommand would still be better.engnadeau commentedon Aug 20, 2025
It's been a couple years since the last comment, has anyone found a good practical solution?
i've been using this in my
~/.zshrcdkarvik commentedon Aug 22, 2025
I ended up somewhere similar. Instead of calling
codethough I justechothe path and then do as I desire from the call. I also store my worktrees within the repo itself and use a local gitignore to hide it. I've also resorted to just using branch name and using the "copy" button on the PR to see it.Usage:
But you could also do
$ code `git getpr foo/bar`ffalor commentedon Feb 23, 2026
Since this is still marked as
core(outside contributors can't create pr's for changes marked core), and the team is not sure if they want to do this yet, I ended up creating an extension for this problem after trying the great options mentioned here.I wanted something that could be used for more than just PR's. The main goal was to quickly spin up a worktree and spawn a Claude code instance in it with the initial prompt. I ended up creating an action concept to make it extensible passed just my use case.
Docs: https://ffalor.github.io/gh-wt/
It supports creating worktrees from PRs, Issues, or just one locally:
gh wt add https://github.com/owner/repo/pull/123gh wt add https://github.com/owner/repo/issues/456gh wt add my-feature-branch@engnadeau use case for opening vscode after creation is a great example of how actions can be used.
gh wt add https://github.com/owner/repo/pull/123 -a vscodeorgh wt run <worktree> <action>to execute actions in already existing worktrees.