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

Viewed 2195

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}'
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.

Related