Joey Aghion

Half a Mind

by Joey Aghion

Find the github pull request for a commit

Inspired by the post Every line of code is always documented, I upgraded my development environment with a few new tools:

  • GitCommitMsg plug-in for Sublime Text - provides easy access to the entire commit history for selected lines.
  • The pr_for_sha command below (stored in my ~/.bash_profile) - If you employ github flow, this command pops open the github page for the pull request where a given commit originated:
export GITHUB_UPSTREAM=artsy

function pr_for_sha {
  git log --merges --ancestry-path --oneline $1..master | grep 'pull request' | tail -n1 | awk '{print $5}' | cut -c2- | xargs -I % open$GITHUB_UPSTREAM/${PWD##*/}/pull/%

Just update GITHUB_UPSTREAM to match whatever you call your upstream repo (e.g., upstream or origin).

And if you’re not already using them, you should of course install these Sublime Text plug-ins (via Package Control):

  • Git - integrates the ever-useful Git Blame command.
  • GitGutter - indicates added, removed, and modified lines right in your editor.