Skip to content

Instantly share code, notes, and snippets.

@moisespsena
Last active August 30, 2018 14:43
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 moisespsena/665b64ef32aad9aad3f38a642eeafe37 to your computer and use it in GitHub Desktop.
Save moisespsena/665b64ef32aad9aad3f38a642eeafe37 to your computer and use it in GitHub Desktop.
Show GIT repositories state recursively
#!/bin/bash
# Show GIT repositories state recursively
if [ "$1" != '' ]; then
cd "$1" || exit $?
fi
find `pwd` -name .git -type d | while read l; do
p=`dirname "$l"`
cd "$p"
sc=0
if [ -n "$(git status --porcelain)" ]; then
# changed
sc=1
state="CHANGED"
else
# not changed, compare local with remote branch
# get current branch name
branch_name=`git rev-parse --abbrev-ref HEAD`
# check if remote branch exists
git show-branch remotes/origin/$branch_name >/dev/null
if [ $? -eq 128 ]; then
# is local branch only
sc=1
state="NEW BRANCH"
else
# compare local with remote
s=`git diff $branch_name origin/$branch_name`
if [ "$s" != '' ]; then
# changed
sc=1
state="REMOTE CHANGED"
else
state=
fi
fi
fi
# if changed, print repo path and state
[ $sc -eq 1 ] && echo "$p -> $state"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment