Skip to content

Instantly share code, notes, and snippets.

@7enderhead
Created October 7, 2024 21:14
Show Gist options
  • Save 7enderhead/beb9c24edbb6d5b4b5f92f8a327e49b1 to your computer and use it in GitHub Desktop.
Save 7enderhead/beb9c24edbb6d5b4b5f92f8a327e49b1 to your computer and use it in GitHub Desktop.
Check Subfolders for Git Status
#!/usr/bin/env bash
# Function to check git status
check_git_status() {
local dir="$1"
cd "$dir" || return
# Check if it's a git repository
if [ -d .git ] || git rev-parse --git-dir > /dev/null 2>&1; then
# Get git status
local status=$(git status --porcelain)
# If there are changes, print the directory name and status
if [ -n "$status" ]; then
echo "Changes in $dir:"
echo "$status"
echo
fi
fi
cd - > /dev/null
}
# Main script
for dir in */; do
if [ -d "$dir" ]; then
check_git_status "$dir"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment