Skip to content

Instantly share code, notes, and snippets.

@carlovsk
Last active July 1, 2025 14:18
Show Gist options
  • Save carlovsk/1b1a1588f7ebebc61869ece7dde7cf53 to your computer and use it in GitHub Desktop.
Save carlovsk/1b1a1588f7ebebc61869ece7dde7cf53 to your computer and use it in GitHub Desktop.
check-git-status.sh
#!/usr/bin/env bash
set -euo pipefail
# ANSI color codes
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
RED='\033[0;31m'
NC='\033[0m' # no color
ROOT="${HOME}/www"
LOG_FILE="${HOME}/Desktop/git_status.log"
# Start fresh log
: > "$LOG_FILE"
echo "Git status report — generated $(date)"
echo "------------------------------------"
printf "%s\n" "Git status report — generated $(date)" >> "$LOG_FILE"
# Find every .git folder and handle it
find "$ROOT" -type d -name .git | while IFS= read -r gitdir; do
repo="${gitdir%/.git}"
cd "$repo"
status_ok=true
notes=()
# 1) any uncommitted (working-tree) changes?
if [[ -n "$(git status --porcelain)" ]]; then
status_ok=false
notes+=("dirty")
fi
# 2) any staged but uncommitted?
if git diff --cached --quiet; then
: # no staged changes
else
status_ok=false
notes+=("staged")
fi
# 3) un-pushed commits?
if git rev-parse --abbrev-ref --symbolic-full-name @{u} &>/dev/null; then
ahead=$(git rev-list --count --left-only @{u}...HEAD)
if (( ahead > 0 )); then
status_ok=false
notes+=("${ahead}↑")
fi
else
notes+=("no-upstream")
fi
# Format output
rel="${repo#$HOME/}"
if $status_ok; then
printf "${GREEN}OK${NC} %s\n" "$rel"
printf "OK %s\n" "$rel" >> "$LOG_FILE"
else
# yellow for a single “dirty” or “staged” note, red otherwise
if ((${#notes[@]} == 1)) && ([[ "${notes[0]}" =~ ^(dirty|staged)$ ]]); then
col=$YELLOW
else
col=$RED
fi
note_str=$(IFS=,; echo "${notes[*]}")
printf "${col}ISSUE${NC} %-30s [%s]\n" "$rel" "$note_str"
printf "ISSUE %-30s [%s]\n" "$rel" "$note_str" >> "$LOG_FILE"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment