Bug fix: cut -d'/' -f2 truncated 'origin/backup/main-*' to just 'backup', so rev-parse always failed and duplicate detection never worked. Fixed with sed to strip 'origin/' prefix properly. New features: - Push unpushed main commits before backing up - Fetch remote backup refs before comparing - Rich summary table: repo, status, commit count, push status, last msg - Color-coded output with dim/bold formatting - Proper cleanup using sed instead of broken cut
3.3 KiB
3.3 KiB
Backup Main Branch Skill
Description: Smart backup of main branches across repositories with duplicate detection.
Script: scripts/backup-main.sh
What It Does
For each of the 3 repositories:
- Switches to
mainand pulls latest - Pushes any unpushed main commits to origin
- Fetches latest remote backup refs
- Skips backup if HEAD matches the latest
backup/main-*branch (smart duplicate detection) - Creates timestamped
backup/main-YYYY-MM-DD-HHMMSSbranch and pushes it - Cleans up old backups (keeps last 7)
- Prints a summary table with: repo name, backup status, total commits, push status, last commit message
Repositories Covered
learning_ai_common_platlearning_voice_ai_agentlearning_multimodal_memory_agents
Quick Start
bash /Users/sd9235/code/mygh/learning_ai_common_plat/scripts/backup-main.sh
Or via Windsurf workflow: /backup-main-branch
Example Output
━━━ learning_ai_common_plat ━━━
Pulling latest...
Pushing 2 unpushed commit(s) on main...
✅ Main pushed
Creating: backup/main-2026-02-12-201500
✅ Pushed to remote
━━━ learning_voice_ai_agent ━━━
Pulling latest...
✅ Already backed up → backup/main-2026-02-12-201500
┌─────────────────────────────────────────────────────────────────────────────────┐
│ BACKUP SUMMARY 2026-02-12 20:15 │
├──────────────────────────┬──────────────────┬─────────┬────────────┬────────────┤
│ Repository │ Backup Status │ Commits │ Main Push │ Last Commit│
├──────────────────────────┼──────────────────┼─────────┼────────────┼────────────┤
│ learning_ai_common_plat │ ✅ New backup │ 142 │ ✅ 2 pushed│ feat(docs) │
│ learning_voice_ai_agent │ ✅ Already backed│ 387 │ up to date │ fix(blob) │
│ learning_multimodal_... │ ✅ New backup │ 98 │ ✅ 4 pushed│ feat(azure)│
└──────────────────────────┴──────────────────┴─────────┴────────────┴────────────┘
Restoration
# List available backups
git branch -r | grep "backup/main-"
# Restore from a specific backup
git checkout -b restore-from-backup origin/backup/main-2026-02-12-201500
git switch main
git merge restore-from-backup
Customization
- Add repos: Edit
REPOSarray inscripts/backup-main.sh - Change retention: Modify
tail -n +8(keep last N) in the cleanup section - Cron:
0 18 * * * bash /Users/sd9235/code/mygh/learning_ai_common_plat/scripts/backup-main.sh
Related Skills
- Debug Service — Backup before major changes
- Production Readiness — Backup before releases