Skip to content

Instantly share code, notes, and snippets.

@brock
Created November 1, 2012 14:31
Show Gist options
  • Save brock/3993967 to your computer and use it in GitHub Desktop.
Save brock/3993967 to your computer and use it in GitHub Desktop.
Open Github Diff comparing current branch to branch specified.
#!/bin/bash
# Save this file somewhere # ~/bin/ghd.sh
# Create an alias in .bashrc # alias ghd='bash ~/bin/ghd.sh'
#
# Usage: ghd <name_of_branch_on_github>
# Browser will open showing you the diff between current branch and the branch specified
DIFF_BRANCH=$1
if [[ -z "$DIFF_BRANCH" ]]; then
echo "Please specifiy a branch to compare."
exit 1
fi
GIT=$(which git)
BRANCH=$($GIT branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
REMOTE=$($GIT remote -v | grep fetch | sed 's/\(.*github.com\)[:|/]\(.*\).git (fetch)/\2/')
open "https://github.com/$REMOTE/compare/$DIFF_BRANCH...$BRANCH"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment