learning_ai_common_plat/AI.dev/SKILLS/backup-main-branch.md
saravanakumardb1 f82afb3872 fix(backup): fix duplicate detection, add push + rich summary table
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
2026-02-12 20:13:57 -08:00

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:

  1. Switches to main and pulls latest
  2. Pushes any unpushed main commits to origin
  3. Fetches latest remote backup refs
  4. Skips backup if HEAD matches the latest backup/main-* branch (smart duplicate detection)
  5. Creates timestamped backup/main-YYYY-MM-DD-HHMMSS branch and pushes it
  6. Cleans up old backups (keeps last 7)
  7. Prints a summary table with: repo name, backup status, total commits, push status, last commit message

Repositories Covered

  • learning_ai_common_plat
  • learning_voice_ai_agent
  • learning_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 REPOS array in scripts/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