Skip to content

PR creation has strange behaviour when remote changes #1032

@chrisfosterelli

Description

@chrisfosterelli

Describe the bug

Using gh pr create after deleting and recreating my origin remote appears to lead to unclear error messages and a new remote for one of the repository's forks being added to my git config.

Steps to reproduce the behavior

I haven't tried to recreate this, just extrapolating from my case info below

  1. Create a feature branch and add some work
  2. Rename the repository on github
  3. Update your remote by removing it and readding it
  4. Attempt to gh pr create from the feature branch

Expected vs actual behavior

I would expect that I can create a pull request, in an ideal world. If something is strange with git, which I presume to be the case causing this, I would expect a better error message and not creating a new remote for a fork.

Instead I get an obscure error message and a new remote :)

Logs

I have been using the new gh pr create to create pull requests. Normally I push the branch up before I do this (though I'm not sure if that's actually required, I guess just my usual flow). When pushing my branch, I noticed github gave a notice: "This repository moved. Please use the new location:".

Github is right that I renamed that repository! I forgot. I thought it'd be good to fix that, so I git remote rm origin and then git remote add origin <correct SSH URL>.

I then go to follow up with a pull request using gh pr create, and get the following behavior:

➜ git:(fix-ispaid) gh pr create

Creating pull request for fix-ispaid into dev in chrisfosterelli/<repo name>

! warning: could not compute title or body defaults: fatal: ambiguous argument 'origin/dev...fix-ispaid': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
git: exit status 128
? Title Predefine isPaid so that user creation doesnt fail
? Body <Received>
? What's next? Submit
Username for 'https://github.com': ^C

The error is unusual, but appears that creation can go ahead as expected. But then I get an HTTP prompt, and suspect something is wrong because I only use SSH remotes. I check the remote that I added, and notice that gh pr create added a new remote for some reason, called fork, which is a fork a colleague made of my repo. It's an HTTP remote.

Very strange behaviour.

I'm able to fix it by git checkout dev && git pull origin dev. Then the gh pr create on my feature branch works normally. Not a big deal, but thought it was worth noting 😄

I imagine this has something to do with deleting the origin remote causing git to no longer have the remote context about origin/dev until I later git checkout dev && git pull origin dev. In either case this has worked with normal git flow doing PRs from the web interface, so I suspect the handling here could be a bit better.

Thanks for reading!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions