WEBTOOLIST.
STATIC WEB PLATFORM
NO ACCOUNTS / NOTHING TO INSTALL

$ webtoolist --script git-repo-status-all

Git Status Across Repositories

Report branch, dirty state, and ahead/behind for every Git repo under a directory.

category DevOps shell Bash 4+ updated 2026-09-14
gitrepositoriesstatusdevops
Safety notes
  • Read-only: runs git status and rev-list only.
  • Large directory trees may take a while; the depth limit keeps it predictable.

Dependencies: git, find

Usage

  • Pass the directory to scan (default: current directory).
  • Set DEPTH to control how deep to search (default 3).

Script

#!/usr/bin/env bash
set -euo pipefail

root="${1:-.}"
depth="${DEPTH:-3}"

find "$root" -maxdepth "$depth" -type d -name .git -print 2>/dev/null \
  | while IFS= read -r gitdir; do
      repo="$(dirname "$gitdir")"
      branch="$(git -C "$repo" branch --show-current 2>/dev/null || echo detached)"
      dirty="$(git -C "$repo" status --porcelain 2>/dev/null | wc -l)"
      ahead="$(git -C "$repo" rev-list --count '@{u}..HEAD' 2>/dev/null || echo 0)"
      behind="$(git -C "$repo" rev-list --count 'HEAD..@{u}' 2>/dev/null || echo 0)"
      printf '%-40s %-20s dirty=%-3s ahead=%-3s behind=%-3s\n' \
        "$repo" "$branch" "$dirty" "$ahead" "$behind"
    done

Example

./git-repo-status-all ~/Projects
DEPTH=5 ./git-repo-status-all /srv

Notes

  • Repos without an upstream report 0 ahead/behind, because the comparison is unavailable.
  • Use git -C PATH fetch first if you care about comparisons with the remote.

Related scripts