Running 'git status' across multiple repos
Simple shell script but very useful. Written using this SO thread as a reference.
Running "find-dirty" will find and check all .git folders under the working directory for either unstaged or uncommitted changes, printing the path if a repository has either.
#!/bin/bash
function unstaged_changes() {
worktree=${1%/*};
git --git-dir="$1" --work-tree="$worktree" diff-files --quiet --ignore-submodules --
}
function uncommited_changes() {
worktree=${1%/*};
git --git-dir="$1" --work-tree="$worktree" diff-index --cached --quiet HEAD --ignore-submodules --
}
function find-dirty () {
for gitdir in `find . -name .git`;
do
worktree=${gitdir%/*};
if ! unstaged_changes $gitdir
then
echo "unstaged $gitdir"
fi
if ! uncommited_changes $gitdir
then
echo "uncommitted $gitdir"
fi
done
}
Written by Dustin Haffner
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Sh
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#