Skip to content

Instantly share code, notes, and snippets.

@benvd
Created January 17, 2014 09:51
Show Gist options
  • Save benvd/8470814 to your computer and use it in GitHub Desktop.
Save benvd/8470814 to your computer and use it in GitHub Desktop.
ggs: git global status. For a set of repos, display whether they are dirty and/or have unpushed commits.
#!/bin/bash
repos=(
"/path/to/a/repo"
"/path/to/another/repo"
)
function isClean {
# Check for unstaged changes, staged changes, untracked files
git diff-files --quiet && git diff-index --quiet --cached HEAD && test -z "$(git ls-files --exclude-standard --others)"
}
function getNumAhead {
# Get the number of unpushed commits on all branches
git log --branches --not --remotes --oneline | wc -l
}
function printRepo {
if isClean ; then
echo -en "\e[00;32m$1\e[00m"
else
echo -en "\e[00;31m$1\e[00m"
fi
numAhead=$(getNumAhead)
if [[ $numAhead -eq 0 ]] ; then
echo ""
else
echo -e " \e[00;33m+$numAhead\e[00m"
fi
}
for i in "${repos[@]}"; do
pushd $i > /dev/null
printRepo `basename $i`
popd > /dev/null
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment