1#!/bin/bash 2 3# Sync script to push changes from Codeberg to GitHub mirror 4# Usage: ./sync-to-github.sh 5 6set -e 7 8RED='\033[0;31m' 9GREEN='\033[0;32m' 10YELLOW='\033[1;33m' 11NC='\033[0m' # No Color 12 13echo -e "${YELLOW}🔄 Syncing Strudel to GitHub mirror...${NC}" 14 15# Check if we're in a git repository 16if [ ! -d ".git" ]; then 17 echo -e "${RED}❌ Error: Not in a git repository${NC}" 18 exit 1 19fi 20 21# Add GitHub remote if it doesn't exist 22if ! git remote get-url github &> /dev/null; then 23 echo -e "${YELLOW}Adding GitHub remote...${NC}" 24 git remote add github https://github.com/calvinw/strudel-llm-mirror.git 25else 26 echo -e "${GREEN}✓ GitHub remote already configured${NC}" 27fi 28 29# Fetch latest from origin (Codeberg) 30echo -e "${YELLOW}📥 Fetching latest from Codeberg...${NC}" 31git fetch origin 32 33# Check if we're on main branch 34current_branch=$(git branch --show-current) 35if [ "$current_branch" != "main" ]; then 36 echo -e "${YELLOW}⚠️ Currently on branch: $current_branch${NC}" 37 echo -e "${YELLOW}Switching to main branch...${NC}" 38 git checkout main 39fi 40 41# Pull latest changes and handle conflicts 42echo -e "${YELLOW}📥 Merging changes from Codeberg...${NC}" 43if ! git pull origin main; then 44 echo -e "${RED}❌ Merge conflicts detected. Please resolve manually.${NC}" 45 exit 1 46fi 47 48# Push to GitHub mirror 49echo -e "${YELLOW}📤 Pushing to GitHub mirror...${NC}" 50if ! git push github main; then 51 echo -e "${YELLOW}⚠️ Push failed. Trying to merge GitHub changes first...${NC}" 52 git fetch github 53 git merge github/main 54 git push github main 55fi 56 57echo -e "${GREEN}✅ Successfully synced to GitHub mirror!${NC}" 58echo -e "${YELLOW}GitHub repo: https://github.com/calvinw/strudel-llm-mirror${NC}"