Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the existing Pull Request ID and Url for specific Branch in GitBash without calling Github API?

I need to find the solution of the exact situation, that has been described in the question.

I only have a feature Branch ID, for which I need to get the Pull Request ID or Url, on GitBash(2.20.1) or Terminal without calling Github API..

I have already tried this, but it doesn't work for every Branch or always, don't know why.

git ls-remote origin 'pull/*/head' | grep -F -f <(git rev-parse HEAD) | awk -F'/' '{print $3}'
like image 977
Vicky Dev Avatar asked Mar 25 '26 13:03

Vicky Dev


1 Answers

but it doesn't work for every Branch or always,

That would be because:

  • either your branch is not part of a GitHub PR branch at all
  • or your branch has new local commits not yet pushed to your PR branch yet, which means the grep (of your local HEAD commit) can only fail.

Instead of grepping, try and check if the PR branch HEAD is part of your current branch history.
See "How to list branches that contain a given commit?"

git fetch origin +refs/pull/*/head:refs/remotes/origin/pr/*
git branch -a --contains <commit>

If you any /pull/ branches, you will get the PR you want.

like image 92
VonC Avatar answered Mar 27 '26 03:03

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!