Last active
August 29, 2015 14:07
-
-
Save zsteinkamp/1ade804cef456cc5810f to your computer and use it in GitHub Desktop.
Push current branch to a GitHub remote then open the GitHub compare page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Push the current branch to a remote with the same branch name then open the | |
| # github page comparing that branch to open a pull request. | |
| # Additional args that are passed to this function are given to the "git push" command. | |
| gpb () | |
| { | |
| remote=$1 | |
| shift | |
| if [ -z $remote ]; then | |
| echo "ERROR: you must specify a remote name" | |
| return | |
| fi | |
| remote_url=$(git config --get remote.$remote.url | sed -e 's/^ssh:\/\///' | sed -e 's/\.git$//' | tr : / ) | |
| if [ -z $remote_url ]; then | |
| echo "ERROR: $remote is not a valid remote name" | |
| return | |
| fi | |
| git_branch=$(git branch 2>/dev/null | sed -n '/^\*/s/^\* //p') | |
| url_branch=$(perl -MURI::Escape -e "print uri_escape(join(' ', @ARGV))" -- $git_branch) | |
| git push $@ $remote $git_branch && open "https://$remote_url/compare/$url_branch?expand=1" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment