Repository navigation
PR creation has strange behaviour when remote changes #1032
Description
Activity
Small update: it turns out that, even after
git checkout dev && git pull origin dev, theghclient no longer displays the error but still creates a brand new remote calledfork. I had to also rungit push origin fix-ispaid && git pull origin fix-ispaidto get it to stop creating theforkremote and successfully create the PR.Thank you for the detailed report! I'm sorry gh is giving you troubles.
I check the remote that I added, and notice that
gh pr createadded a new remote for some reason, calledfork, which is a fork a colleague made of my repo. It's an HTTP remote.Do you happen to have write access to your colleague's fork? This might have triggered the logic in which gh prefers to push branches to forks where you have write access instead of to the parent repo. #800
But then I get an HTTP prompt, and suspect something is wrong because I only use SSH remotes.
You may want to set
gh config set git_protocol sshto have gh always default to generating SSH-style git URLs. However, I don't think this alone will fix your problem withfork.I think that for now, you should keep using the workaround where you first push the branch
git push origin HEADand thengh pr create.- addedmore-info-neededMore info needed from user/contributorMore info needed from user/contributor
on May 28, 2020 I'm sorry gh is giving you troubles.
Overall it's working great and this was just a small blip 😄
Do you happen to have write access to your colleague's fork?
It looks like I do, though I don't think it was explicitly given to me, rather I believe I have it implicitly because my repository is private. Looks like that is by design:
Private forks inherit the permissions structure of the upstream or parent repository. For example, if the upstream repository is private and gives read/write access to a team, then the same team will have read/write access to any forks of the private upstream repository. This helps owners of private repositories maintain control over their code.
If it helps, this is the repo structure here:
chrisfosterelli/project-api (private main repo with new name) \-> colleague/project-lambda (colleague's fork, who hasn't updated the name)You may want to set gh config set git_protocol ssh to have gh always default to generating SSH-style git URLs.
Thanks for the tip!
I think you're right it seems tightly related to #800, though I don't know if it's precisely a duplicate. That issue seems to be when there is a primary org repository and no fork under the author's namespace, as they've chosen not to fork. In my case, the main repo is the one directly under my namespace, but it has tried pushing to my colleagues fork.
I think the git error message that comes up during the attempt to create a PR prior to re-pulling
devis also separate.Just rereading and saw your note here in #800 (comment):
you can always choose a push target by first pushing with git
If a manual push to a specific remote ever isn't respected as PR head, please open a separate issue. 🙇
That's an interesting point and I think what I've been doing, and where the issue came in was that I saw the notice from Github during the push, and then changed my remote but didn't repush prior to
gh pr create(and FWIW I don't suspect most people would think to as I'd figure it has to do with the remote data rather than local git data)
Describe the bug
Using
gh pr createafter deleting and recreating myoriginremote appears to lead to unclear error messages and a newremotefor 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
gh pr createfrom the feature branchExpected 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 createto 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 originand thengit 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: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 createadded a new remote for some reason, calledfork, 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 thegh pr createon 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
originremote causing git to no longer have the remote context aboutorigin/devuntil I latergit 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!