top | item 9869548

(no title)

halisaurus | 10 years ago

Assuming functions count:

    # git branch ahead/behind another
    function gahead() {
      # use first argument or master
      original=${1-master}

      # use the second argument or current branch if not given
      current=`git branch | grep \* | sed s/\*\ //`
      compare=${2-$current}

      # run git rev-list and capture numbers returned
      result=`git rev-list --left-right --count $original...$compare`

      # print numbers in a pretty message
      numbers=($result);
      echo -e "$Red-$Color_Off $compare is currently $IRed${numbers[0]}$Color_Off commits behind $original";
      echo -e "$Green+$Color_Off $compare is currently $IGreen${numbers[1]}$Color_Off commits ahead of $original";
    }
Edit: if it's not clear you would use this like:

    $ gahead #checks current branch against master
    $ gahead development #checks current branch against development
    $ gahead development foo #checks foo branch against development
NB: this is checking local branches, not remote branches.

discuss

order

No comments yet.