Skip to content

Instantly share code, notes, and snippets.

@wheresrhys
Forked from andrewjtait/gist:9114245e92b84d69aa43
Last active August 29, 2015 14:08
Show Gist options
  • Save wheresrhys/2bd4ae944003fe57af50 to your computer and use it in GitHub Desktop.
Save wheresrhys/2bd4ae944003fe57af50 to your computer and use it in GitHub Desktop.
bash function for viewing current git branch on github
function gh {
branch="$(git rev-parse --abbrev-ref HEAD)"
url="$(git config --get remote.origin.url)"
url=${url/[email protected]:/http://github.com/}
url=${url/.git/}
if [[ $1 =~ "-c" ]]; then action="compare"
elif [[ $1 =~ "-p" ]]; then action="pull"
else action="tree"; fi
if [[ $2 != "" ]]; then base="$2..."
else base=""; fi
url="${url}/${action}/${base}${branch}"
echo "Opening ${url} $(\open ${url})"
}
@wheresrhys
Copy link
Author

api

gh // open tree in github
gh -c // open comparison in github
gh -p // open pull request in github
gh [-c|-p] branch-name // open comparison or pr with branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment