Skip to content

Instantly share code, notes, and snippets.

@mcaskill
Forked from mzabriskie/README.md
Last active December 7, 2015 17:51
Show Gist options
  • Save mcaskill/8dc2ebfeaaeaed3d96d5 to your computer and use it in GitHub Desktop.
Save mcaskill/8dc2ebfeaaeaed3d96d5 to your computer and use it in GitHub Desktop.
View a summary of the status for multiple repositories.

Name

git-multi-status — View a summary of the status for multiple repositories.

Usage

git-multi-status [<options>…​] [--] [<path>…​]

Description

Displays a summary of the status for multiple Git repositories located in a specified path or from the current directory.

Useful for projects with multiple dependencies.

Options

TBD

#!/bin/bash
dir="$1"
# No directory has been provided, use current
if [ -z "$dir" ]
then
dir="`pwd`"
fi
# Make sure directory ends with "/"
if [[ $dir != */ ]]
then
dir="$dir/*"
else
dir="$dir*"
fi
# Loop all sub-directories
for f in $dir
do
# Only interested in directories
[ -d "${f}" ] || continue
echo -en "\033[0;35m"
echo "${f}"
echo -en "\033[0m"
# Check if directory is a git repository
if [ -d "$f/.git" ]
then
mod=0
cd $f
git fetch
# Display current branch
# if [ $(git symbolic-ref --short -q HEAD) -ne 0 ]
# then
echo -en "\033[0;36m"
echo $(git symbolic-ref --short -q HEAD)
echo -en "\033[0m"
# fi
# Check for remote commits
if [ $(git status | grep behind -c) -ne 0 ]
then
echo -en "\033[0;33m"
echo "— Your branch is behind."
# echo "— Incoming files"
echo -en "\033[0m"
fi
# Check for local commits
if [ $(git status | grep ahead -c) -ne 0 ]
then
echo -en "\033[0;32m"
echo "— Your branch is ahead."
# echo "— Incoming files"
echo -en "\033[0m"
fi
# Check for modified files
if [ $(git status | grep modified -c) -ne 0 ]
then
mod=1
echo -en "\033[0;31m"
echo "— Modified files"
echo -en "\033[0m"
fi
# Check for untracked files
if [ $(git status | grep Untracked -c) -ne 0 ]
then
mod=1
echo -en "\033[0;31m"
echo "— Untracked files"
echo -en "\033[0m"
fi
# Check if everything is peachy keen
if [ $mod -eq 0 ]
then
echo "— Nothing to commit"
fi
cd ../
else
echo "— Not a Git repository"
fi
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment