Skip to content

Instantly share code, notes, and snippets.

@aroberts
Forked from jcordasc/rec_git_status.sh
Created June 29, 2012 13:58
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save aroberts/3018100 to your computer and use it in GitHub Desktop.
Save aroberts/3018100 to your computer and use it in GitHub Desktop.
Script for checking git status of many git repositories
#!/bin/bash
# usage: $0 source_dir [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="."
else
ARGS=$@
fi
for i in $ARGS ; do
for gitdir in `find $i -name .git` ; do
( working=$(dirname $gitdir)
cd $working
RES=$(git status | grep -E '^# (Changes|Untracked|Your branch)')
STAT=""
grep -e 'Untracked' <<<${RES} >/dev/null 2>&1
if [ $? -eq 0 ] ; then
STAT=" $red[Untracked]$reset"
fi
grep -e 'Changes not staged for commit' <<<${RES} >/dev/null 2>&1
if [ $? -eq 0 ] ; then
STAT="$STAT $red[Modified]$reset"
fi
grep -e 'Changes to be committed' <<<${RES} >/dev/null 2>&1
if [ $? -eq 0 ] ; then
STAT="$STAT $green[Staged]$reset"
fi
grep -e 'Your branch is ahead' <<<${RES} >/dev/null 2>&1
if [ $? -eq 0 ] ; then
STAT="$STAT $yellow[Unpushed]$reset"
fi
grep -e 'Your branch is behind' <<<${RES} >/dev/null 2>&1
if [ $? -eq 0 ] ; then
STAT="$STAT $cyan[Unmerged]$reset"
fi
if [ -n "$STAT" ] ; then
echo -e "$working :$STAT"
fi
)
done
done
@aroberts
Copy link
Author

Updated this useful snipped from jcordasc to fit with my git install (1.7.7.5)

@aroberts
Copy link
Author

aroberts commented Jul 9, 2012

Added color and empty args behavior

@c0wfunk
Copy link

c0wfunk commented Sep 6, 2012

I can't seem to get this to work with more than one directory. I've tried various syntax combos ..

ARGS=('folder1' 'folder2')

and also

ARGS[0]='folder1'
ARGS[1]='folder2'

But I can't seem to get it to search past the first folder. I'm not that experienced with bash scripting - how do I make this for statement loop through the array?

@c0wfunk
Copy link

c0wfunk commented Sep 7, 2012

Figured it out .. see https://gist.github.com/3666392

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment