Files
homelab/setup-git-dual-remote.sh
T
2026-02-13 19:41:46 +02:00

37 lines
1.1 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Configure homelab repo to push to both Gitea (local) and remote (e.g. GitHub)
# Run once after: git init && git add . && git commit -m "Initial homelab config"
#
# Usage: ./setup-git-dual-remote.sh [gitea_url] [remote_url]
# Example: ./setup-git-dual-remote.sh https://git.zea.lt/USER/homelab.git https://github.com/USER/homelab.git
set -e
GITEA_URL="${1:?Usage: $0 <gitea_repo_url> <remote_repo_url>}"
REMOTE_URL="${2:?Usage: $0 <gitea_repo_url> <remote_repo_url>}"
cd "$(dirname "$0")"
if [[ ! -d .git ]]; then
echo "Initializing git..."
git init
git add .
git commit -m "Initial homelab infrastructure" || true
fi
# Remove default origin if it exists (e.g. from clone)
git remote remove origin 2>/dev/null || true
# Add origin with dual push URLs one push goes to both
git remote add origin "$GITEA_URL"
git remote set-url --add --push origin "$GITEA_URL"
git remote set-url --add --push origin "$REMOTE_URL"
echo "Dual remote configured."
echo " Local (Gitea): $GITEA_URL"
echo " Remote backup: $REMOTE_URL"
echo ""
echo "Create both repos first (empty, no readme). Then:"
echo " git branch -M main"
echo " git push -u origin main"