Last active
June 23, 2020 15:36
-
-
Save skwid138/416120dd1bccf93001c13d5cdeec8240 to your computer and use it in GitHub Desktop.
Git How far local branch is behind/ahead of remote branch
This file contains 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
#!/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