ewz5zq
Last Updated: February 25, 2016
·
1.487K
· dhaffner

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
}