-
-
Save ramananbalakrishnan/be74b96ab1700114493a to your computer and use it in GitHub Desktop.
check the status of all git repositories located under a given directory (default: cwd)
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 | |
# usage: $0 [source_dir] ... | |
# where source_dir args are directories containing git repositories | |
red="\033[00;31m" | |
green="\033[00;32m" | |
yellow="\033[00;33m" | |
blue="\033[00;34m" | |
purple="\033[00;35m" | |
cyan="\033[00;36m" | |
reset="\033[00m" | |
if [ $# -eq 0 ] ; then | |
ARGS=`find -maxdepth 2 -name .git | sort | sed 's/\(.*\)\.git/\1/'` | |
else | |
ARGS=$@ | |
fi | |
if [ ! -n "$ARGS" ] ; then | |
echo "No git repositories found" | |
fi | |
for i in ${ARGS[@]} ; do | |
for gitdir in `find $i -name .git` ; do | |
( working=$(dirname $gitdir) | |
cd $working | |
RES=$(git remote update > /dev/null 2>&1 & git status | grep -E '(Changes|Untracked|Your branch)') | |
STAT="" | |
echo "$RES" | grep -e 'Untracked' >/dev/null 2>&1 | |
if [ $? -eq 0 ] ; then | |
STAT=" $red[Untracked]$reset" | |
fi | |
echo "$RES" | grep -e 'Changes not staged for commit' >/dev/null 2>&1 | |
if [ $? -eq 0 ] ; then | |
STAT="$STAT $red[Modified]$reset" | |
fi | |
echo "$RES" | grep -e 'Changes to be committed' >/dev/null 2>&1 | |
if [ $? -eq 0 ] ; then | |
STAT="$STAT $green[Staged]$reset" | |
fi | |
echo "$RES" | grep -e 'Your branch is ahead' >/dev/null 2>&1 | |
if [ $? -eq 0 ] ; then | |
STAT="$STAT $yellow[Unpushed]$reset" | |
fi | |
echo "$RES" | grep -e 'Your branch is behind' >/dev/null 2>&1 | |
if [ $? -eq 0 ] ; then | |
STAT="$STAT $cyan[Unmerged]$reset" | |
fi | |
echo "$RES" | grep -e 'up-to-date' >/dev/null 2>&1 | |
if [ $? -eq 0 ] ; then | |
STAT="$STAT $blue[Up-to-date]$reset" | |
fi | |
if [ -n "$STAT" ] ; then | |
echo -e "$working :$STAT" | |
fi | |
) | |
done | |
done |
git remote update
is added to L28 to fetch remote refs . (most probably will slow down the script)
I just read the blog post about this, wanted to let you know you can make it work just find on OSX and other non-GNU find systems by adding a .
to the first find
command.
See here: https://gist.github.com/jrumbut/df259655130a579cfdcc3bfb05beed66
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
source_dir
is provided