Skip to content

Instantly share code, notes, and snippets.

@ramananbalakrishnan
Forked from c0wfunk/git-multi-status.sh
Last active June 22, 2016 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ramananbalakrishnan/be74b96ab1700114493a to your computer and use it in GitHub Desktop.
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)
#!/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
@ramananbalakrishnan
Copy link
Author

  • use current directory if no source_dir is provided
  • print message if no suitable git repositories found
  • print up-to-date directories as well

@ramananbalakrishnan
Copy link
Author

  • git remote update is added to L28 to fetch remote refs . (most probably will slow down the script)

@jrumbut
Copy link

jrumbut commented Jun 22, 2016

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