Skip to content

default repo should be inferred  #8659

Open

Description

@jtnord

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

  1. gh repo clone jenkinsci/pom
  2. cd pom
  3. gh repo fork
  4. git remote -v
  5. 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   

Activity

  1. added
    bug
    on Feb 2, 2024
  2. added
    needs-triage
    on Feb 2, 2024
  3. williammartin commented on Feb 2, 2024

    @williammartin
    Member

    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

    So just to be clear, if you gh repo clone a 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 fork as 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?

  4. added
    more-info-needed
    and removed
    needs-triage
    on Feb 2, 2024
  5. max-ishere commented on Feb 13, 2024

    @max-ishere

    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 ran gh repo unarchive (because I archive if I don't intend to contribute anymore), it said: repo is not archived. I had to run gh repo set-default my-fork even 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)

  6. max-ishere commented on Feb 13, 2024

    @max-ishere

    #8440 descibes my usecase pretty much

  7. max-ishere commented on Feb 13, 2024

    @max-ishere

    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.

  8. williammartin commented on Feb 14, 2024

    @williammartin
    Member

    @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.

  9. jtnord commented on Feb 24, 2024

    @jtnord
    Author

    So just to be clear, if you gh repo clone a fork, the default is automatically set to the upstream.

    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) :)

    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?

    pretty much that's the workflow for authoring/creating... (NB: I am not pushing to a branch on upstream ever, 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 upstream cloned. 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.

  10. added
    needs-triage
    and removed
    more-info-needed
    on Jun 4, 2024
  11. cli-triage commented on Jul 9, 2026

    @cli-triage
  12. added
    enhancement
    on Jul 9, 2026
  13. github-actions commented on Jul 9, 2026

    @github-actions
    Contributor

    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 wanted Contributions 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.

  14. removed
    needs-triage
    on Jul 9, 2026
  15. waldyrious commented on Sep 3, 2026

    @waldyrious
    Contributor

    Note: this comment was originally posted in #13006, but I moved it here where it fits better.

    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 plain git clone <upstream>), e.g. for building locally or doing deep code searches; then, if I have something worth contributing, I run a gh fork alias that I've set locally (which stands for gh 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 next gh pr create (as would gh pr checkout) greets me with the "run gh repo set-default" nag.

    As @williammartin points out, gh repo clone indeed 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 as upstream and sets it as base. However, in a clone-the-upstream-then-fork flow like mine above, the cloned repo typically isn't a fork, so gh repo clone does not set a default.

    To me this seems to be clearly a gap in gh repo fork: its --clone path sets the default repo, but the plain "add a remote to the repo I'm already in" path doesn't. I agree that gh repo fork should set the default repo when creating a new fork (or adding an existing fork remote), just like what gh repo fork --clone <upstream> and gh 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 🥲.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions