Created
August 12, 2026 13:08
-
-
Save novica/e455d0870063b6219663a30ee0c4e179 to your computer and use it in GitHub Desktop.
git-status — run a quick audit of folder with many git projects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # git-status — run a quick audit of folder with many git projects | |
| #!/usr/bin/env bash | |
| #!/usr/bin/env bash | |
| RED=$'\033[31m' | |
| GREEN=$'\033[32m' | |
| YELLOW=$'\033[33m' | |
| CYAN=$'\033[36m' | |
| BOLD=$'\033[1m' | |
| RESET=$'\033[0m' | |
| current_group="" | |
| printf "${BOLD}%-25s %-15s %-10s %-15s${RESET}\n" "REPO" "BRANCH" "STATUS" "AHEAD/BEHIND" | |
| while IFS= read -r -d '' repo; do | |
| group=$(dirname "$repo") | |
| if [ "$group" != "$current_group" ]; then | |
| current_group="$group" | |
| echo "" | |
| echo "${BOLD}${CYAN}== $group ==${RESET}" | |
| fi | |
| branch=$(git -C "$repo" rev-parse --abbrev-ref HEAD 2>/dev/null) | |
| dirty=$(git -C "$repo" status --porcelain -uno 2>/dev/null) | |
| if [ -n "$dirty" ]; then | |
| status="${RED}dirty${RESET}" | |
| else | |
| status="${GREEN}clean${RESET}" | |
| fi | |
| ab=$(git -C "$repo" rev-list --left-right --count '@{u}...HEAD' 2>/dev/null) | |
| if [ -z "$ab" ]; then | |
| ahead_behind="${YELLOW}no upstream${RESET}" | |
| else | |
| behind=$(echo "$ab" | cut -f1) | |
| ahead=$(echo "$ab" | cut -f2) | |
| if [ "$ahead" = "0" ] && [ "$behind" = "0" ]; then | |
| ahead_behind="${GREEN}up to date${RESET}" | |
| else | |
| ahead_behind="${YELLOW}↑${ahead} ↓${behind}${RESET}" | |
| fi | |
| fi | |
| printf " %-25s %-15b %-10b %-15b\n" "$(basename "$repo")" "$branch" "$status" "$ahead_behind" | |
| done < <(find . -type d -exec test -d '{}/.git' \; -prune -print0 | sort -z) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment