Skip to content

Instantly share code, notes, and snippets.

@skwid138
Last active June 23, 2020 15:36
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save skwid138/416120dd1bccf93001c13d5cdeec8240 to your computer and use it in GitHub Desktop.
Git How far local branch is behind/ahead of remote branch
#!/bin/bash
###
# Use -r to compare against a remote branch
###
## Example w/o this script
## git fetch --all | git rev-list --left-right --count origin/master...master
$USAGE="$0 [-r <remote branch>]"
## Current Branch Name
CURRENTBRANCH=$(git rev-parse --symbolic-full-name --abbrev-ref HEAD)
## Branch to Compare Against Current Branch
COMPAREBRANCH=$1
echo "current branch $CURRENTBRANCH";;
echo "compare branch $COMPAREBRANCH";;
while getopts ":r" option
do
case "${option}" in
r) COMPAREBRANCH="origin/${$1}";;
\?) echo "ERROR: Invalid option: $USAGE"
exit 1;;
esac
done
echo "compare branch $COMPAREBRANCH";;
#git fetch --all | git rev-list --left-right --count $COMPAREBRANCH...$CURRENTBRANCH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment