Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 95c88d77cd
Fetching contributors…

Cannot retrieve contributors at this time

executable file 56 lines (47 sloc) 1.819 kB
#!/bin/bash
#
# Usage: push
#
# Send your local branch changes to the remote branch,
# and copy the relevant GitHub 'compare' URL to your clipboard (!)
# This is Mac-only for the time being
#
# Any extra args to this command will be passed through to 'git push',
# e.g. for doing "push -f"
#
# TODO DRY this b/w pull and push
branch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/') || exit $?
default_remote="origin"
remote=$(git config "branch.${branch}.remote" || echo "$default_remote")
remote_branch=$( (git config "branch.${branch}.merge" || echo "refs/heads/$branch") | awk -F '/' '{ print $3 }' )
# Push & save output
push=$(git push --set-upstream $* $remote $remote_branch 2>&1)
exit_code=$?
if [ $exit_code != 0 ]; then
echo "Ouch, push failed! code=$exit_code, output=$push"
exit $exit_code
elif echo $push | grep "Everything up-to-date" >/dev/null; then
echo "git says everything is up-to-date!"
exit 0
fi
# Parse relevant commit refs and let user know what we did
# 1st-time push to new branch gets special treatment
if echo $push | grep "\[new branch\]" >/dev/null; then
refs="master...$branch"
echo "Pushed new branch '$branch' remotely"
else
refs=$(echo $push | awk '{ print $3}' | sed 's/\.\./\.\.\./')
echo $push
fi
# Parse output into a sexy GitHub compare URL!
remote_url=$(git remote show $remote -n | grep Push | awk '{ print $3 }')
if [[ "$remote_url" =~ "github.com" ]]; then
repo_name=$(echo $remote_url | sed 's/.*\:\(.*\)\.git/\1/')
github_url="https://github.com/$repo_name/compare/$refs"
copied="Compare URL copied to clipboard!"
which pbcopy >& /dev/null && echo $github_url | pbcopy && echo $copied
which xclip >& /dev/null && echo $github_url | xclip -selection clipboard && echo $copied
echo $github_url
echo
fi
exit 0
Jump to Line
Something went wrong with that request. Please try again.