Skip to content

Instantly share code, notes, and snippets.

@th0rgall
Created February 16, 2021 10:15
Show Gist options
  • Save th0rgall/74c683c7171fc1b91bd1f688e2d8d9c7 to your computer and use it in GitHub Desktop.
Save th0rgall/74c683c7171fc1b91bd1f688e2d8d9c7 to your computer and use it in GitHub Desktop.
# git branch behind & ahead - a shell function
# inspired on https://stackoverflow.com/questions/20433867/git-ahead-behind-info-between-master-and-branch
# usage: gitba branchA...branchB
gitba () {
echo "$(cut -d '.' -f 4 <<<"$1") is compared to $(cut -d '.' -f 1 <<<"$1")"
REVLIST="$(git rev-list --left-right --count $1)"
echo $(cut -f 1 <<<"$REVLIST" | cut -f 1) commits behind.
echo $(cut -f 2 <<<"$REVLIST" | cut -f 2) commits ahead.
}
# Example output:
# feature/custom-footer is compared to main
# 200 commits behind.
# 1 commits ahead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment