Skip to content

Instantly share code, notes, and snippets.

@oh-sky
Created February 26, 2015 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oh-sky/944a277e424b7318d2e7 to your computer and use it in GitHub Desktop.
Save oh-sky/944a277e424b7318d2e7 to your computer and use it in GitHub Desktop.
トピックブランチのmasterからの遅れを調べる
#!/bin/bash
REMOTE_NAME='origin'
git fetch --prune ${REMOTE_NAME}
msg=''
for remote_branch in `git branch -r | grep -v '\->'| grep ${REMOTE_NAME}/`
do
ahead=0
behind=0
for rev in `git rev-list --left-right ${remote_branch}...${REMOTE_NAME}/master`
do
if test $(echo $rev | grep -e '^<') ; then
ahead=`expr $ahead + 1`
else
behind=`expr $behind + 1`
fi
done
#本当は下記のようにしたいのだが、grep -cが何故か1しか返さず上記ループで妥協
#rev_list=`git rev-list --left-right ${remote_branch}...${REMOTE_NAME}/master`
#ahead=`echo ${rev_list} | grep -c '<'`
#behind=`echo ${rev_list} | grep -c '>'`
if test $ahead -gt 0 ; then
echo "${remote_branch} is ${behind} commit(s) behind ${REMOTE_NAME}/master"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment