How can I query git to find out which branches contain a given commit? gitk will usually list the branches, unless there are too many, in which case it just say
The answer for git branch -r --contains works well for normal remote branches, but if the commit is only in the hidden head namespace that GitHub creates for PRs, you'll need a few more steps.
Say, if PR #42 was from deleted branch and that PR thread has the only reference to the commit on the repo, git branch -r doesn't know about PR #42 because refs like refs/pull/42/head aren't listed as a remote branch by default.
In .git/config for the [remote "origin"] section add a new line:
fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
(This gist has more context.)
Then when you git fetch you'll get all the PR branches, and when you run git branch -r --contains you'll see origin/pr/42 contains the commit.