Git-getpull: Quickly find the pull request that merged your commit to master
by Andrew Warner


You pyonged “Andrew Warner – Git-getpull: Quickl...”

Save Note No Thanks
Caution: You are now annotating this song as

Ideally git blame would give you all the context you need to determine why some code was written. But the reality is that no team is perfectly disciplined, and sometimes you're going to run across commits with cryptic or ambiguous messages ("bugfix," anyone?).

When a git commit message doesn't provide enough context, or provides context at the wrong level (too much what, too little why), it's useful to be able to find the GitHub pull request that merged that commit. Pull requests can contain code review comments, discussion over implementation details, before/after pictures of the UI, and more. Pull requests may also have many commits associated with them, which together give a clearer sense of the intended change.

The git-getpull utility allows you to find out which pull request merged a commit into master.


$ curl -o /usr/local/bin/git-getpull && chmod +x /usr/local/bin/git-getpull


$ git getpull 42a3817c

Annotated Code!

Click the highlighted bits for more information.


if [ -z "$1" ]; then
  echo "Usage: git getpull <SHA>"
  exit 1
elif [ -z "$(git rev-parse --git-dir 2>/dev/null)" ]; then
  echo "Not in a git directory"
  exit 1
  repository_path=$(git config --get remote.origin.url 2>/dev/null | \
   perl -lne 'print $1 if /(?:(?:https?:\/\/\/)|:)(.*?).git/')
  pull_id=$(git log $1..master --ancestry-path --merges --oneline 2>/dev/null \
  | tail -n 1 | perl -nle 'print $1 if /#(\d+)/')

  if [ -n "$pull_id" ]; then
    echo "$pull_base_url/$pull_id"
    echo "Sorry, couldn't find that pull"
    exit 1

Edit news description to add:

  • Historical context: how the event or text affects the world and history
  • An explanation of the work's overall story (example: "Here, President Obama confirms the legality of drone strikes...")
  • The work's impact on current issues
This text has been changed by someone else. Copy your work to your clipboard and click here to reload.