jevstrudel.git / sync-to-github.sh
1#!/bin/bash

Sync script to push changes from Codeberg to GitHub mirror Usage: ./sync-to-github.sh

6set -e
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}"

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

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

Fetch latest from origin (Codeberg)

30echo -e "${YELLOW}📥 Fetching latest from Codeberg...${NC}"
31git fetch origin

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

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

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
57echo -e "${GREEN}✅ Successfully synced to GitHub mirror!${NC}"
58echo -e "${YELLOW}GitHub repo: https://github.com/calvinw/strudel-llm-mirror${NC}"