You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
gh pr [comment] not working correctly for few days #8758
For few days (~10, potentially related to 2.44.1?) I have strange behaviors with the gh pr [comment] command.
Because it's attached to a private project, I can't share complete example, but I had two issues:
gh pr comment -b "rfm" done from a repository branch sent the comment rfm to a completely different PR, totally unrelated to my branch
gh pr comment -b "rfm" refused to create a comment with the message no pull requests found for branch "main". However, the pr has been created using gh pr create ….
The problem is this is not for all branches, all PRs… so I can't provide a clear reproducer.
I had to transform my command into gh pr comment (git rev-parse --abbrev-ref HEAD) -b "rfm" to make it work.
Expected vs actual behavior
Expected behavior is for gh pr to resolve the PR like it was the case in the past.
Logs
For the second case, the only log I have is no pull requests found for branch "main".
Please, ask for test if you want more details, because I can't share links to private registries, even if it's on GitHub.com.
Hey @davinkevin, thanks for opening this issue and sorry for the trouble, that sounds very annoying. What you're describing is very strange and I can't think of any change that has gone in recently that would impact the pr comment command.
It would be extremely useful if you could catch one of these in the wild with GH_DEBUG=api turned on (and redacting any proprietary information from the output).
Is there anything else you might have changed about your workflow recently? If you go back to release 2.43.1 for a bit I wonder if you'd still experience this.
And I didn't change anything in my workflow recently. The strange part is this is not all the time the same problem. It may work for one branch, not work at all on another one… or just select the wrong branch and push comment to the wrong PR 😅
…ase-tasks-resources-are-adjusted-to-avoid-CPUThrottling-and-memory-overprovionning-:main via 🅶 v8.7-20240212001320+0000 via 🅺 872ms
❯ gh pr status
Relevant pull requests in gradle/ge
Current branch
#22123 not-my-branch-nor-pr [main] - Closed
Created by you
#32692 `database-tasks` resources are adjusted to avoi... [kdavin/32685-database-tasks-resources-are-adjusted-to-avoid-CPUThrottling-and-memory-overprovionning-]
× 1/2 checks failing ✓ 1 Approved ✓ Auto-merge enabled
…
Requesting a code review from you
…
It stated my branch is #22123, which is not the case. PR is #32692
So the obvious fix is to make sure that you are tracking the right upstream branch by running this from your current branch and then trying to comment again:
Hmmm, I wouldn't expect the commands you've provided there to result in this unless you have branch.autoSetupMerge configured to track (which I don't think is the default). It could also happen if you git push -u or git branch -u. Anyway, it certainly seems like something in your local flow that is resulting in this, and if we track that down everything should work again.
But should gh understand it?
I don't see how gh could figure this out. You've configured git to say that origin/main is your remote tracking branch.
PS: it would be cool to have this directly and official in gh, like GitLab already has 😇
Can you give an example of the glab command you'd use?
I do use the push.autoSetupRemote FYI, but not branch.autoSetupMerge.
I've updated my create-branch workflow, let's see how this works.
But I'm still surprised it worked for some branches, and even posted to other PR 🤷
Can you give an example of the glab command you'd use?
My workflow with glab is usually:
$ glab issue create
… do things in the terminal …
$ glab mr create --related-issue <number of the prev issue>
…
After that, I have my branch created, setup correctly by GitLab (right remote branch, not like the cause of this issue). It's the processed I tried to automate with my create-branch function.
This appears to be a confirmed bug with gh pr comment branch resolution - either targeting the wrong PR or failing to find the PR for the current branch. No confident duplicate was found (issue #7590 covers related branch-detection problems in gh pr status/gh pr view, but is a distinct enough scenario). I'm suggesting priority-3 because a workaround exists (passing the branch name explicitly: gh pr comment $(git rev-parse --abbrev-ref HEAD) -b "..."), the issue is intermittent without a clear reproducer, and it affects a limited set of configurations. If anyone can narrow down a consistent reproduction case - ideally with gh version output, OS, and the remote/branch configuration in use - that would help a maintainer investigate further.
Going to close this out due to housekeeping (it seems like it was an environmental issue upon skimming the issue). If there's still a problem that we can fix in gh, a new issue to describe what we should enhance would be helpful 🙏
Activity
[-]`gh pr comment` not working correctly for few days[/-][+]`gh pr [comment]` not working correctly for few days[/+]williammartin commentedon Feb 26, 2024
Hey @davinkevin, thanks for opening this issue and sorry for the trouble, that sounds very annoying. What you're describing is very strange and I can't think of any change that has gone in recently that would impact the
pr commentcommand.It would be extremely useful if you could catch one of these in the wild with
GH_DEBUG=apiturned on (and redacting any proprietary information from the output).Is there anything else you might have changed about your workflow recently? If you go back to release
2.43.1for a bit I wonder if you'd still experience this.davinkevin commentedon Feb 26, 2024
Find attached the output of the command
gh pr comment -b rfm.I've redacted data, but I tried to keep the same value for every redacted data.
FYI, the one not selected in this PR is totally unrelated to my work (
PR_kwDOAnM6XM5N0mPL) 😅.davinkevin commentedon Feb 26, 2024
And it's not better with the previous version:
And I didn't change anything in my workflow recently. The strange part is this is not all the time the same problem. It may work for one branch, not work at all on another one… or just select the wrong branch and push comment to the wrong PR 😅
williammartin commentedon Feb 26, 2024
While I'm investigating, what happens if you run
gh pr vieworgh pr status?williammartin commentedon Feb 26, 2024
And what is the output of this command?
davinkevin commentedon Feb 26, 2024
The first one doesn't work at all:
And the other one is broken:
It stated my branch is
#22123, which is not the case. PR is#32692davinkevin commentedon Feb 26, 2024
I had to quote it because of incompatibility with
fish:williammartin commentedon Feb 26, 2024
Re: #8758 (comment)
Yep, that all makes sense with the way
pr commentis failing (I just wanted to check that this wasn't specific topr comment).Re: #8758 (comment)
Ok I can see what is happening here (though I'm not sure why we are in this state). The second line of your screenshot says:
This branch config (you can see it if you
cat .git/configand search for your branch name tells git that your local branchkdavin/32685-database-tasks-resources-are-adjusted-to-avoid-CPUThrottling-and-memory-overprovionning-is tracking the remote branchmain.. The GitHub CLI is reading this config to fill in the GraphQL request to figure out which PR to comment on. You can see the GraphQL variables in your debug output that theheadRefNameismain.So the obvious fix is to make sure that you are tracking the right upstream branch by running this from your current branch and then trying to comment again:
You can revert this by doing:
The question really is though, how did you end up with your branch in this state? What workflows do you use for creating and working with branches?
davinkevin commentedon Feb 26, 2024
Got it. Indeed after running the command
branch -u …it fixed it.My process to create my branch is wrapped in a
ghextension, and to summarize it does this:With all values provided as parameters:
And I think it's because
origin/mainas base branch translates to remote branch… instead of local. So it's the reason behind this issue.But should
ghunderstand it?PS: it would be cool to have this directly and official in
gh, likeGitLabalready has 😇williammartin commentedon Feb 26, 2024
Hmmm, I wouldn't expect the commands you've provided there to result in this unless you have
branch.autoSetupMergeconfigured totrack(which I don't think is the default). It could also happen if yougit push -uorgit branch -u. Anyway, it certainly seems like something in your local flow that is resulting in this, and if we track that down everything should work again.I don't see how
ghcould figure this out. You've configured git to say thatorigin/mainis your remote tracking branch.Can you give an example of the
glabcommand you'd use?davinkevin commentedon Feb 26, 2024
I do use the
push.autoSetupRemoteFYI, but notbranch.autoSetupMerge.I've updated my
create-branchworkflow, let's see how this works.But I'm still surprised it worked for some branches, and even posted to other PR 🤷
My workflow with
glabis usually:After that, I have my branch created, setup correctly by
GitLab(right remote branch, not like the cause of this issue). It's the processed I tried to automate with mycreate-branchfunction.cli-triage commentedon Jul 9, 2026
This appears to be a confirmed bug with
gh pr commentbranch resolution - either targeting the wrong PR or failing to find the PR for the current branch. No confident duplicate was found (issue #7590 covers related branch-detection problems ingh pr status/gh pr view, but is a distinct enough scenario). I'm suggestingpriority-3because a workaround exists (passing the branch name explicitly:gh pr comment $(git rev-parse --abbrev-ref HEAD) -b "..."), the issue is intermittent without a clear reproducer, and it affects a limited set of configurations. If anyone can narrow down a consistent reproduction case - ideally withgh versionoutput, OS, and the remote/branch configuration in use - that would help a maintainer investigate further.BagToad commentedon Jul 9, 2026
Going to close this out due to housekeeping (it seems like it was an environmental issue upon skimming the issue). If there's still a problem that we can fix in
gh, a new issue to describe what we should enhance would be helpful 🙏