
Stop Playing Git Repository Hide-and-Seek: A 5-Minute Script That'll Save Your Sanity
Created at: September 24, 2025
Picture this: You're deep in code, switching between your client project, that cool side project, your job work, and maybe your college projects. You make changes here, commit there, push somewhere else... and then panic hits.
"Wait, did I commit those database changes? Did I push the API fixes? Which repo was I working on yesterday?"
Sound familiar? Welcome to the Git Repository Juggling Olympics – where everyone's a participant, but nobody signed up.
The Mess We All Know Too Well
Managing multiple git repositories is like trying to remember which pocket you put your keys in, except you have 47 pockets and they're all in different jackets scattered around your house.
Traditional solutions? GUI tools that eat your RAM for breakfast, or manually running `git status` in every single directory like some kind of digital archaeologist.
Enter: The Sanity Saver Script
Here's a shell script that does the boring stuff so you don't have to:
#!/bin/bash
# Define the path to search for git repositories
SEARCH_PATH="$HOME/code"
# Colors for output formatting
RED='\033[0;31m'
YELLOW='\033[1;33m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
echo "Scanning for git repositories in: $SEARCH_PATH"
echo ""
# Find all directories containing .git folders
git_repos=()
while IFS= read -r -d '' dir; do
# Remove the /.git suffix to get the repository root
repo_path="${dir%/.git}"
git_repos+=("$repo_path")
done < <(find "$SEARCH_PATH" -name ".git" -type d -print0 2>/dev/null)
if [ ${#git_repos[@]} -eq 0 ]; then
echo "No git repositories found in $SEARCH_PATH"
exit 0
fi
echo "Found ${#git_repos[@]} git repositories"
echo ""
# Arrays to store repositories with different statuses
unstaged_repos=()
unpushed_repos=()
staged_repos=()
# Function to check git status
check_git_status() {
local repo_path="$1"
local repo_name=$(basename "$repo_path")
# Change to repository directory
cd "$repo_path" || return 1
# Get git status output
status_output=$(git status 2>/dev/null)
# Check for unstaged changes
if echo "$status_output" | grep -q "Changes not staged for commit:"; then
unstaged_repos+=("$repo_name")
return
fi
# Check for staged changes (uncommitted)
if echo "$status_output" | grep -q "Changes to be committed:"; then
staged_repos+=("$repo_name")
return
fi
# Check for unpushed changes
if echo "$status_output" | grep -q "(use \"git push\" to publish your local commits)"; then
unpushed_repos+=("$repo_name")
return
fi
}
# Check each repository
echo "Checking repository statuses..."
for repo in "${git_repos[@]}"; do
if [ -d "$repo" ]; then
check_git_status "$repo"
fi
done
echo ""
echo "=== GIT REPOSITORY STATUS REPORT ==="
echo ""
# Display results in table format
printf "%-30s %-20s\n" "Repository" "Status"
printf "%-30s %-20s\n" "----------" "------"
# Show repositories with unstaged changes
for repo in "${unstaged_repos[@]}"; do
printf "%-30s ${RED}%-20s${NC}\n" "$repo" "Unstaged Changes"
done
# Show repositories with staged but uncommitted changes
for repo in "${staged_repos[@]}"; do
printf "%-30s ${YELLOW}%-20s${NC}\n" "$repo" "Staged Changes"
done
# Show repositories with unpushed commits
for repo in "${unpushed_repos[@]}"; do
printf "%-30s ${YELLOW}%-20s${NC}\n" "$repo" "Unpushed Commits"
done
echo ""
echo "Summary:"
echo "- Repositories with unstaged changes: ${#unstaged_repos[@]}"
echo "- Repositories with staged changes: ${#staged_repos[@]}"
echo "- Repositories with unpushed commits: ${#unpushed_repos[@]}"
total_issues=$((${#unstaged_repos[@]} + ${#staged_repos[@]} + ${#unpushed_repos[@]}))
total_repos=${#git_repos[@]}
synced_repos=$((total_repos - total_issues))
echo "- Synced repositories: $synced_repos"
echo "- Total repositories: $total_repos"What Makes This Script Awesome
No More Mental Gymnastics: Instead of remembering which of your 23 projects has changes, just run the script and see exactly what needs fixing.
Color-Coded Chaos: Red for "oh no," yellow for "almost there," and sweet silence for repos that are behaving properly.
Zero Fluff: Only shows repositories that need attention. No need to scroll through 20 "everything's fine" status messages.
One Command, All Answers: Run it once, know everything. Perfect for that pre-meeting panic check.
Pro Tips for Maximum Effectiveness
Save it as git_status_checker.sh, make it executable (chmod +x git_status_checker.sh), and alias it to something short like gitcheck in your shell config.
Run it every morning with your coffee, before important meetings, or whenever that nagging feeling hits that you've forgotten to commit something important.
The Bottom Line
Life's too short to play hide-and-seek with your git repositories. This script turns project chaos into organized productivity, giving you back those precious brain cycles for actual coding instead of repository archaeology.d
Now stop reading and go save yourself some sanity! Your future stressed-out self will thank you.
Latest Posts
Reliable Password Backups with Git Hooks and Systemd Timers
