# Git Auto-Sync Setup for Second Brain Automatically sync vault changes between server, desktop, and phone using Git. ## How It Works ``` Desktop/Phone Changes → Git Repo ← Server Auto-Commits ↓ All devices sync ``` ## Server Setup ### 1. Install Auto-Sync Service ```bash sudo cp /workspace/second-brain/git-auto-sync.service /etc/systemd/system/ sudo systemctl daemon-reload sudo systemctl enable git-auto-sync.service sudo systemctl start git-auto-sync.service # Verify sudo systemctl status git-auto-sync.service ``` ### 2. Watch Auto-Commits ```bash # View logs sudo journalctl -fu git-sync # Example output: # [2026-04-26 07:45:30] Changes detected: # M 03-learnings/architecture.md # A 00-inbox/new-idea.md # ✓ Committed # ✓ Pushed to remote ``` ## Desktop Setup ### 1. Clone the Vault ```bash # First time git clone ssh://user@server:/workspace/second-brain ~/Obsidian/second-brain # Or if using Local Sync, configure it to pull from this git repo ``` ### 2. Pull Latest Changes ```bash cd ~/Obsidian/second-brain git pull ``` ### 3. Auto-Pull (Optional) **macOS/Linux:** ```bash # Add to crontab (every 5 minutes) crontab -e */5 * * * * cd ~/Obsidian/second-brain && git pull -q 2>/dev/null ``` **Or use a Git hook:** ```bash cat > .git/hooks/post-merge << 'EOF' #!/bin/bash # Auto-sync after merge echo "✓ Vault synced" EOF chmod +x .git/hooks/post-merge ``` ## Phone Setup ### With Obsidian + Local Sync Plugin 1. **On Server:** - Make sure git repo is accessible (or use Gitea) 2. **On Phone:** - Install "Local Sync" plugin in Obsidian - Configure it to sync with: `ssh://user@server:/workspace/second-brain` - Or configure with Gitea URL 3. **On Desktop:** - Same setup, pull regularly --- ## Sync Strategies ### Strategy 1: Git-Only (Recommended) - Server auto-commits all changes - Desktop: `git pull` manually or via cron - Phone: Local Sync pulls from server git ```bash # Desktop cron (every 5 min) */5 * * * * cd ~/Obsidian/second-brain && git pull -q ``` ### Strategy 2: Obsidian + Local Sync - Desktop + Phone: Use Obsidian's Local Sync plugin - Server: Git auto-sync mirrors changes **Advantage:** Real-time sync on devices, server keeps git history ### Strategy 3: Git + SSH Pull - Desktop/Phone: SSH git clone - Pull before opening Obsidian - Push changes after editing ```bash #!/bin/bash # pre-open-obsidian.sh cd ~/Obsidian/second-brain git pull open ~/Obsidian/second-brain # macOS ``` --- ## Remote Repository (Gitea / GitHub) ### Configure Remote Push **If using Gitea on your server:** ```bash # On server cd /workspace/second-brain git remote add gitea ssh://git@gitea-server/your-repo.git # Verify git remote -v # Push existing commits git push -u gitea master ``` **Then on desktop/phone:** ```bash git clone ssh://git@gitea-server/your-repo.git ``` --- ## Monitoring Syncs ### View Recent Commits ```bash cd /workspace/second-brain git log --oneline -10 ``` ### Check Sync Status ```bash # See what's staged but not committed git status # See changes in last hour git log --since="1 hour ago" --oneline ``` ### Manual Sync Test ```bash # On desktop: make a change echo "test" >> 00-inbox/test.md git add . git commit -m "Test sync" git push # On server: should auto-pull (if configured) cd /workspace/second-brain git log --oneline -1 ``` --- ## Conflict Resolution If both server and desktop edit the same file: ```bash # Server (auto-sync) will get it first # Desktop pulls and sees conflict marker: <<<<<<< HEAD desktop version ======= server version >>>>>>> origin/master # Manually resolve, then: git add . git commit -m "Resolved conflict" git push ``` --- ## Disable Auto-Sync (if needed) ```bash sudo systemctl stop git-auto-sync.service sudo systemctl disable git-auto-sync.service ``` --- ## Performance Notes - **Poll interval:** 30 seconds (adjustable) - **Commit overhead:** ~50ms per check - **Memory:** ~64MB (limited) - **CPU:** ~10% max --- Created: 2026-04-26