I have an old branch locally on my computer, I am interested in checking if that branch has (or had) a PR (open, merged or closed) to our GitHub repo. The repo is set as the remote origin.

How can I detect this using either the gh or git interfaces?

My organization uses the "Squash and Merge" feature when merging PRs into our GitHub main branch. I think this means that one cannot check the git log to see if a local branch commit is present in the main branch's log, since only the squashed PR commit is merged into main.

Assuming the above is possible, it would be lovely be able to quickly identify which any of my local branches are not merged.

I tried using git switch main; git pull; git log | grep <commit-id-from-local-branch> (for future inclusion in a bash script) but arrived at the above squash-and-merge conclusion.

I tried exploring the gh CLI functionality, but couldn't find something that checked my current branch, only currently open PRs (gh pr status).

1

There are 1 answers

0
Bill Huneke On

if GH is squashing your PR commits and merging to main, then technically there was (or is still) a ref there that has all the original commits in it. If you know the PR id for the pull requests you are interested in, you might still be able to fetch the original branch before it was squashed.

Read here: How to fetch from deleted branch of closed pull request

Without that, the squash has of course eliminated most of the information you need for verifying your commits are pushed. But, assuming PRs on your GH tended to merge without conflicts, you might be able to do a simple test and get your answer pretty quickly...

The simpler idea would be this: checkout origin/main and try merging each of your local branches into your copy of the latest main. If your local branch merges to main without introducing any changes, then you have answer - that particular local branch is (more or less) superfluous and you can delete it.