Git hook to produce Github "Create Pull Request" link in terminal like Bitbucket Does

Created my own local hook that works well enough for my needs. Add this as a pre-push hook to your local clone of a repo:

#!/bin/sh

branch=$(git rev-parse --abbrev-ref HEAD)
userRepo=$(git remote -v | grep fetch | awk '{print $2}' | grep "github.com" | cut -d':' -f2 | rev | cut -c5- | rev)

if [ -n "$userRepo" ]
then
    echo ""
    echo "Create PR at: https://github.com/$userRepo/compare/$branch?expand=1"
    echo ""
fi

Example output:

$ git push origin testouthooks

Create PR at: https://github.com/pzelnip/dotfiles/compare/testouthooks?expand=1

Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 284 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:pzelnip/dotfiles.git
f7c29b8..f6f9347  testouthooks -> testouthooks

I can then hit that url emitted to land on the create pull request page in Github with the branch I just pushed as the source branch.

This isn't quite equivalent to Bitbucket, as it's run locally (the Bitbucket one is run on the remote) so it's not as intelligent (ex: it still emits the URL even if the push resulted in no changes on the remote, etc). But it suits my need of "when I push to a Github repo, I can click a link from my terminal window to get to the create PR page in Github".