skwid138
10/24/2018 - 2:05 PM

Git How far local branch is behind/ahead of remote branch

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