See the git status of a directory tree
If you have a bunch of repos in a directory and can't remember which have uncommited/unpushed cruft use this alias. Works great when coming back from leave and not remembering what you were working on. Drop this function and alias into ~/.bashrc
or ~/.zshrc
and then use gstatus
on the commandline.
git_status()
{
NC='\033[0m'
RED='\033[0;31m'
BLUE='\033[0;34m'
GREEN='\033[0;32m'
for d in `ls`; do
j=0
if [ -d $d/.git ]
then
cd $d
if [[ "$(git status | grep modified)" != "" ]]
then
if [ $j -eq 0 ]
then
echo ""
echo "Directory: $d "
j=1
fi
echo ""
m="$(git status | grep modified)"
echo -e "$RED $m $NC"
fi
if [[ "$(git status | grep 'is ahead of')" != "" ]]
then
if [ $j -eq 0 ]
then
echo ""
echo "Directory: $d "
j=1
fi
n="$(git status | grep 'ahead of' | grep -oE '[0-9]+')"
echo -e "\t$BLUE `git branch | grep \* | awk '{ print $2 }'` $NC is $BLUE $n $NC commit(s) ahead of origin"
fi
if [[ "$(git ls-files --others --exclude-standard)" != "" ]]
then
if [ $j -eq 0 ]
then
echo ""
echo "Directory: $d "
j=1
fi
for f in `git ls-files --others --exclude-standard`; do
echo -e "\t$GREEN untracked: $f $NC"
done
fi
cd ..
fi
done
}
alias gstatus=git_status
Written by mattjones
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Git
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#