#!/bin/bash

# Load SSH config
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa_overtones

# Set remote origin if not exists
if ! git remote show | grep -q "origin"; then
    git remote add origin ssh://overtones@81.17.103.239:1979/home/overtones/public_html
fi

# Fetch remote branches
git fetch origin

# Check if remote master branch exists, if not, create it
if ! git branch -r | grep -q "origin/master"; then
    git push origin master:master
fi

# Update the remote URL to ensure it's correctly set
git remote set-url origin ssh://overtones@81.17.103.239:1979/home/overtones/public_html

# Push to remote (local 'master' branch to remote 'master' branch)
git push -f origin master:master