Repository navigation
Open
Labels
Description
Describe the bug
Currently it is very combersome when working with newly cloned repositories as you need to always set the default after you clone in order to use commands like gh pr checkout nnn
gh version -> 2.42.0
The default should only need to be set if it is something unusual - and working with the origin (or upstream as gh likes to call it) would be the normal workflow (you generally would not default to opening PRs on a fork!)
Steps to reproduce the behavior
- gh repo clone jenkinsci/pom
- cd pom
- gh repo fork
- git remote -v
- gh pr checkout 334
see the error
Expected vs actual behavior
expected:
the PR 334 is checkout out from the main (not forked) repository.
either infer this from the fork relationship in the GH UI, or default to either the repository defined by origin or upstream
actual:
X No default remote repository has been set for this directory.
please run `gh repo set-default` to select a default remote repository.
Logs
❯ gh repo clone jenkinsci/pom
Cloning into 'pom'...
remote: Enumerating objects: 3004, done.
remote: Counting objects: 100% (1465/1465), done.
remote: Compressing objects: 100% (89/89), done.
Receiving objects: 100% (3004/3004), 626.62 KiB | 2.22 MiB/s, done.sed 1539
Resolving deltas: 100% (1716/1716), done.
❯ cd pom\
C:\w\s\g\t\pom ☸ docker-desktop default master gh repo fork 13:35:06
! jtnord/pom already exists
? Would you like to add a remote for the fork? Yes
✓ Added remote origin
❯ git remote -v
origin https://github.com/jtnord/pom.git (fetch)
origin https://github.com/jtnord/pom.git (push)
upstream https://github.com/jenkinsci/pom.git (fetch)
upstream https://github.com/jenkinsci/pom.git (push)
❯ gh pr checkout 334
X No default remote repository has been set for this directory.
please run `gh repo set-default` to select a default remote repository.
C:\w\s\g\t\pom ☸ docker-desktop default master
Reacted by Jesse Glick, Hervé Le Meur, Aarni Koskela, Marcel Partap and Peter Valadez
Reacted by Marcel Partap
Reacted by Marcel Partap
Activity
williammartin commentedon Feb 2, 2024
So just to be clear, if you
gh repo clonea fork, the default is automatically set to the upstream.In your case, you are getting a repository with no upstream and then forking it. It would seem to make sense to do that in the case of
gh repo forkas well.Regardless, I'd like to understand a little bit more about what your workflow is here. I'm guessing a more common workflow where you would run into this would be
repo clone upstream,gh repo fork,do some commits on a branch,gh pr create?max-ishere commentedon Feb 13, 2024
I ran into this issue today when I ran
gh repo fork(already forked by me before), at the "clone fork?" prompt I said yes. Then rangh repo unarchive(because I archive if I don't intend to contribute anymore), it said: repo is not archived. I had to rungh repo set-default my-forkeven though originally the clone was supposed to be of my fork and thus I expect that the default repo would be set to my-fork and not upstream. (I'm using my-fork as a placeholder)max-ishere commentedon Feb 13, 2024
#8440 descibes my usecase pretty much
max-ishere commentedon Feb 13, 2024
Also I feel like regardless of permission errors, when it asks you "do you want to clone the fork" I assume that it will from this point on consider the git repo as the fork and not the upstream. It would be even more embarrassing or confusing to change properties for upstream when you thought you were working on the fork.
williammartin commentedon Feb 14, 2024
@max-ishere can you write a single comment providing full context into the state of the remote and locally cloned repos. I don't have the full picture in my head of the workflow you are describing. If #8440 is more appropriate then please write it there, thank you.
jtnord commentedon Feb 24, 2024
my use case is I would always clone the non fork first, but if you want to use either the fist thing you clone or the GH fork relationship to infer the default they both work for me (as in 99% of cases it will be the same) :)
pretty much that's the workflow for authoring/creating... (NB: I am not pushing to a branch on
upstreamever, I may or may not have access rights - but generally the accepted practice is to use branches from forks for PRs (the reasons why are not important here, but after all this should not be an uncommon workflow)).Then the other workflow is the one that I described in the summary where I have already got
upstreamcloned. There may or may not be other remotes (for forks) defined also (for which I may be working on a branch that is not a PR base for example), and I want to checkout someone else's PR to do something with it locally.cli-triage commentedon Jul 9, 2026
github-actions commentedon Jul 9, 2026
Thank you for your issue! We have categorized it as an enhancement (feature or improvement) request, and it has been added to our backlog. In doing so, we are not committing to implementing this feature at this time, but, we will consider it for future releases based on community feedback and our own product roadmap.
Unless you see the help wantedContributions welcome
label, we are not currently looking for external contributions for this feature.
If you come across this issue and would like to see it implemented, please add a thumbs up! This will help us prioritize the feature. Please only comment if you have additional information or viewpoints to contribute.
waldyrious commentedon Sep 3, 2026
Thanks for opening this! I often run into the exact same friction and would love to see it smoothed out.
My workflow is exactly like yours: I normally clone the upstream (either
gh repo clone <upstream>or plaingit clone <upstream>), e.g. for building locally or doing deep code searches; then, if I have something worth contributing, I run agh forkalias that I've set locally (which stands forgh repo fork --remote --remote-name waldyrious, as was recommended to me way back in #847) to fork the repo if I don't have one yet, or just add my fork as a remote if it already exists. That way I don't need to manually fork the repo in the GitHub UI first. But the result is that I end up with two GitHub remotes and no default set, so the nextgh pr create(as wouldgh pr checkout) greets me with the "rungh repo set-default" nag.As @williammartin points out,
gh repo cloneindeed sets the default repo — but that only happens if the repo you clone is already a fork, e.g. if you had forked it in the GitHub UI first. In that case, it adds the parent asupstreamand sets it as base. However, in a clone-the-upstream-then-fork flow like mine above, the cloned repo typically isn't a fork, sogh repo clonedoes not set a default.To me this seems to be clearly a gap in
gh repo fork: its--clonepath sets the default repo, but the plain "add a remote to the repo I'm already in" path doesn't. I agree thatgh repo forkshould set the default repo when creating a new fork (or adding an existing fork remote), just like whatgh repo fork --clone <upstream>andgh repo clone <fork>do. (Of course, it should only do that when no default is set yet, so it never overrides a deliberate choice.)Would something along those lines be acceptable? I'd really love to see this issue addressed, as it is something that has been bugging me for literal years 🥲.