Skip to content

How to change base repo for gh pr? #2300

Description

@mehagar

Describe the bug

I originally used the gh pr create command, which prompted me to pick a base repo. I picked my forked repo instead of the upstream one, and now I'm unsure how to change the base repo so I don't need to prefix every command with --repo. Is there any way to do this?

Steps to reproduce the behavior

  1. Fork some repo
  2. Clone repo locally
  3. create local branch
  4. gh pr create
  5. Pick the forked repo as base.

Expected vs actual behavior

I expected there to be a command like gh repo set or something that will let me configure what the base repo for pushing should be.

Logs

Activity

  1. added
    coreThis issue is not accepting PRs from outside contributors
    enhancementa request to improve CLI
    and removed
    bugSomething isn't working
    on Oct 27, 2020
  2. samcoe commented on Oct 27, 2020

    @samcoe
    Contributor

    @mehagar At this time that is not a feature that gh supports. It is a good idea though and we will evaluate if it is something we want to add support for in the future.

  3. jetersen commented on Oct 27, 2020

    @jetersen

    Where is this setting stored so we can manually change it?

    I have selected the wrong base repository several times.

    Perhaps the selection could be more specific base repo for me suggests that I should pick my fork. Where if it asked for upstream repo, I would not question the selection.

  4. mislav commented on Oct 27, 2020

    @mislav
    Contributor

    @jetersen @mehagar The cached preference is called gh-resolved can be unset in your local repo with:

    git config --local --get-regexp '\.gh-resolved$' | cut -f1 -d' ' | xargs -L1 git config --unset
    

    I'm sorry for the nuisance. We'll try to expose this better so that it's easier to change!

    Ref. #2090 #1864

  5. rivy commented on Dec 6, 2020

    @rivy

    git config --local --get-regexp '.gh-resolved$'

    That construction isn't platform portable (because of the single-quotes and shell-specific utilities).
    Use git config --local --unset "remote.origin.gh-resolved" to remove the setting.

  6. henryiii commented on Jan 13, 2021

    @henryiii

    Use git config --local --unset "remote.origin.gh-resolved" to remove the setting.

    This didn't actually work for me, everything was still targeting my fork. The original construction above did work. Would love for an official, discoverable way to do this, as it's very confusing once it ever gets set incorrectly! The prompt for "base repo" is similar to "where should we push this repo", so it's easy to set it wrong.

  7. rivy commented on Jan 14, 2021

    @rivy

    @henryiii , the configuration key name remote.origin.gh-resolved would be the default/usual one. But, if you named your remote something different, that would alter the needed command. Replacing "origin" with whatever local name that you've given your remote repository and the construction should work. @mislav's construction wipes all the key for all remotes. But, off-hand, I don't know of a way to remove all keys matching a regex from git's config in a cross-platform compatible manner.

  8. henryiii commented on Jan 28, 2021

    @henryiii

    Ahh, so it's an entry inside .git/config. I'd looked there, but was looking for a section called gh, not an entry under the remotes. Okay, makes much more sense now. Still would love an "official" way to undo a mistake! I constantly answer the first question with where I want to push to, and whenever it was actually asking for the base, that's exactly the wrong answer. And even though seeing the second question immediately lets me realize that I must have answered the first question wrong, if you Control-C out, it's too late, the base is set.

  9. mislav commented on Jan 28, 2021

    @mislav
    Contributor

    @henryiii Yes, it's inside git's own config. We typically avoid putting gh-related configuration into git, but for this specific case, putting it inside git config meant that the cached bit is preserved even if the repository moves on disk or if its remotes get renamed.

    Absolutely, I believe that gh should have a dedicated command to let you undo or change a base repo choice. We'll update this thread once we have something. 👍

  10. henryiii commented on Jan 28, 2021

    @henryiii

    Sounds great! Just reverting the change if you control-C out before you finish after answering all the questions but have answered that one question incorrectly would fix it 90% of the time for me. :)

  11. mislav commented on Jan 28, 2021

    @mislav
    Contributor

    @henryiii That is actually a great idea. Mind submitting a separate bug report for that? <3

  12. sunopar commented on Mar 21, 2021

    @sunopar

    In my opinion we can add this to the doc.

  13. neiljp commented on May 20, 2021

    @neiljp

    I appreciate the detail of where this is stored now being described above, and I understand this is a little complex since it's a user setting that one might want to persist with the local clone - but to need to look in the issues for how to change or remove this config setting is rather bad.

    If gh is going to mess with my local .git then it should at minimum be documented (in manual, perhaps as a note in gh config output, certainly appended to output after being set), and ideally be configurable in gh config. Is that the plan for v1 and v2?

  14. jjb commented on Sep 24, 2021

    @jjb

    For those having trouble getting the right git config ... invocation: you can just open .git/config in a text editor, find the [remote "USERNAME"] section (where USERNAME is your github username), and remove gh-resolved = base

  15. henryiii commented on Sep 24, 2021

    @henryiii
    git config --edit

    Will get you there, too.

  16. ssbarnea commented on Dec 12, 2021

    @ssbarnea

    I think that we need a gh pr reset or another smart way to allow user to correct it. I face this quite often and I will never be able to remember the very long workaround for unconfiguring the current wrong default remote. Maybe even a info text mentioning how to reset it would do?

    Still 50+ votes and no solution is bad. This clearly indicates that the current experience is bit lacking and that is not an isolated issue.

    For the moment I added

    alias gh-pr-reset="git config --local --get-regexp '\.gh-resolved$' | cut -f1 -d' ' | xargs -L1 git config --unset"
    
  17. georgettica commented on Dec 12, 2021

    @georgettica

    @ssbarnea If you look there are many PR's related to that, so it's trying to get solved by the community

  18. nille02 commented on Apr 24, 2022

    @nille02

    one and a half year later we are still with the same problem. i edited the .git/config file and move the gh-resolved = base to the correct repo.

  19. added a commit that references this issue on May 14, 2022
  20. mislav commented on Dec 22, 2022

    @mislav
    Contributor

    Thanks everyone for your feedback and sorry for the nuisance that was having to edit .git/config manually. In the most recent release, there is now the gh repo set-default --unset command for this. Please leave further feedback here #6777

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

Metadata

Metadata

Assignees

Labels

coreThis issue is not accepting PRs from outside contributorsenhancementa request to improve CLI

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions