Find a Pull Request on GitHub where a commit was originally created Find a Pull Request on GitHub where a commit was originally created git git

Find a Pull Request on GitHub where a commit was originally created


You can just go to GitHub and enter the SHA into the search bar, make sure you select the "Issues" link on the left.

UPDATED 13 July 2017

Via the GitHub UI there is a now a really easy way to do this. If you are looking at a commit in the list of commits in a branch in the UI, click on the link to the commit itself. If there is a PR for that commit and it wasn't added directly to the branch, a link to the PR listing the PR number and the branch it went into will be directly under the commit message at the top of the page.enter image description here


Example of finding a PR by clicking on a link to the commit

If you have the commit SHA and nothing else and don't want to go digging around for it, just add /commit/[commit SHA] to the repo url, and you will see the commit page, with the PR link if it exists.For example, if the SHA is 52797a7a3b087231e4e391e11ea861569205aaf4 and the repo is https://github.com/glimmerjs/glimmer-vm , then go to https://github.com/glimmerjs/glimmer-vm/commit/52797a7a3b087231e4e391e11ea861569205aaf4


git config --add remote.origin.fetch +refs/pull/*/head:refs/remotes/origin/pull/*git fetch origingit describe --all  --contains <COMMIT>

If necessary, change origin to the name of the remote that points to theGitHub repository to which the pull request would have been sent. The firstcommand only needs to be run once for any given remote, and the second willgenerally be done when getting other updates.

This will cause git to get information about pull requests along with actualbranches. They'll show up as remote-tracking branches like origin/pull/123.Once that is done, you can use git describe with the --all and --containsoptions to show the first branch which has the referenced commit.

However, this won't work if the commit you're looking for is actually amodified version of the commit from the pull request such as if the changeswere rebased onto other work or the person doing the merge decided to make somechanges.


Since Oct. 13, 2014, this should be straightforward:

For example:

You can see for the file hakimel/reveal.js/plugin/markdown/markdown.js, my contribution now comes with a reference to the PR #734 it originated.

PR from contrib

This comes from Linking merged pull requests from commits:

We've been including the containing branches and tags on commit pages to give you more context around changes. Now, commits in a repository's default branch will also show you the pull request that introduced them.

commit with PR reference in it!

In the pull request, you can see the discussion around why the commit was introduced, and get a clearer picture of the reason for the change.

As always, if you know the commit SHA, you can skip the commit page and search for the pull request directly.