# Get previous branch prev=$(git rev-parse --abbrev-ref @{-1})
# Get current branch current=$(git rev-parse --abbrev-ref HEAD)
# Get remote URL, assumes ssh remote=$(git config --get remote.origin.url)
# Replace some parts remote=${remote/git@github.com:/} remote=${remote/\.git/}
# Final URL url=https://github.com/$remote/compare/$prev...$current?expand=1
# Output to screen echo$url
# Mac OSX copy to clipboard with pbcopy ( which pbcopy >/dev/null 2>&1 ) && echo"$url" | pbcopy && echo"[+] Copied to clipboard"
# Linux copy to both the selection buffer and clipboard with xclip. ( which xclip >/dev/null 2>&1 ) && echo"$url" | xclip -i -sel c -f |xclip -i -sel p && echo"[+] Copied to clipboard"