3

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}'
Vicky Dev
  • 1,893
  • 2
  • 27
  • 62

1 Answers1

1

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250