Git Repository Management Scripts
Quick Start
# 1. Make scripts executable
chmod +x git_cleanup.sh quick_push.sh git_status.py
# 2. Preview what would happen (ALWAYS DO THIS FIRST)
./git_cleanup.sh --dry-run --all
# 3. Push all unpushed commits
./quick_push.sh
# or
./git_cleanup.sh --push
# 4. Generate fresh status report
python3 git_status.py --root ~/ --format markdown > git-status-report.md
Scripts Overview
git_status.py - Repository Scanner
Scans directories for git repos and generates reports.
# Simple text output
python3 git_status.py --root ~/PROJECTS
# Markdown report with full details
python3 git_status.py --root ~/ --format markdown > report.md
# JSON for programmatic use
python3 git_status.py --root ~/ --format json --output repos.json
# All formats at once
python3 git_status.py --root ~/ --format all --output-dir ./reports
# Custom stale threshold (14 days instead of default 30)
python3 git_status.py --root ~/ --stale-days 14 --format markdown
git_cleanup.sh - Batch Operations
Performs batch git operations safely.
# ALWAYS preview first
./git_cleanup.sh --dry-run --push
./git_cleanup.sh --dry-run --all
# Push unpushed commits
./git_cleanup.sh --push
# Fix diverged repos (interactive)
./git_cleanup.sh --fix-diverged
# Show .gitignore suggestions
./git_cleanup.sh --gitignore
# Clean untracked files (DESTRUCTIVE - be careful!)
./git_cleanup.sh --clean-untracked --dry-run # Preview first!
./git_cleanup.sh --clean-untracked # Actually delete
# All safe operations
./git_cleanup.sh --all
# Non-interactive mode (for scripts)
./git_cleanup.sh --push --non-interactive
quick_push.sh - Fast Push
Simple script to push all Coditect submodules. No options, just run it.
./quick_push.sh
Recommended Workflow
Daily
# Check status
python3 git_status.py --root ~/PROJECTS --format simple
# Push any unpushed work
./quick_push.sh
Weekly
# Full report
python3 git_status.py --root ~/ --format markdown > ~/git-status-$(date +%Y-%m-%d).md
# Review and push
./git_cleanup.sh --dry-run --all
./git_cleanup.sh --all
Monthly
# Full audit with stale detection (14 days)
python3 git_status.py --root ~/ --format all --stale-days 14 --output-dir ~/git-audits/
# Review stale repos for archival
Fixing Common Issues
Issue: PROJECTS repo is diverged (+25/-27)
cd ~/PROJECTS
git fetch origin
git status
# Option 1: Rebase (recommended if your changes are small)
git rebase origin/main
git push
# Option 2: Merge (safer, creates merge commit)
git merge origin/main
git push
# Option 3: Force push (DANGEROUS - overwrites remote)
git push --force-with-lease
Issue: halcasteel repo has 3,643 untracked files
Your home directory is a git repo catching too many files. Fix:
cd ~
cat >> .gitignore << 'EOF'
PROJECTS/
Library/
Applications/
Desktop/
Documents/
Downloads/
Movies/
Music/
Pictures/
Public/
.Trash/
.cache/
.npm/
.local/
.config/
*.log
EOF
git add .gitignore
git commit -m "chore: Update gitignore to exclude system directories"
Issue: Submodules have migration artifacts
Each has 1 untracked file from the lowercase naming migration:
# Preview what would be deleted
./git_cleanup.sh --clean-untracked --dry-run
# If safe, clean them
./git_cleanup.sh --clean-untracked
Issue: PROJECTS repo has 24,779 untracked files
The ~/PROJECTS directory shouldn't be a git repo—it contains nested repos.
Option A: Remove git tracking from PROJECTS
cd ~/PROJECTS
rm -rf .git
Option B: Keep it but ignore nested repos
cd ~/PROJECTS
echo '*/' >> .gitignore
git add .gitignore
git commit -m "chore: Ignore subdirectories"
File Locations
After running, scripts create files in these locations:
| Script | Output |
|---|---|
git_status.py --format markdown | stdout or --output file |
git_status.py --format all | --output-dir (default: current dir) |
git_cleanup.sh | No files, just git operations |
Safety Notes
- Always use
--dry-runfirst to preview changes --clean-untrackedis DESTRUCTIVE - it permanently deletes files- Force pushing overwrites remote history - only use if you're sure
- Backup important work before batch operations
- Review the repo lists in
git_cleanup.shbefore running
Customization
Edit git_cleanup.sh to modify the repo lists:
# Line ~30: Repos with unpushed commits
UNPUSHED_REPOS=(...)
# Line ~45: Diverged repos
DIVERGED_REPOS=(...)
# Line ~50: Dirty repos for stash
DIRTY_REPOS=(...)
# Line ~60: Migration artifact repos
MIGRATION_ARTIFACT_REPOS=(...)
Edit git_status.py function categorize_repo() to customize category detection.