diff --git a/repo_watcher.sh b/repo_watcher.sh index cd8246f..64bd5cf 100644 --- a/repo_watcher.sh +++ b/repo_watcher.sh @@ -21,12 +21,17 @@ process_repo() { # Detect the default branch dynamically DEFAULT_BRANCH=$(git remote show origin | awk '/HEAD branch/ {print $NF}') + # Check if the branch exists locally, and if not, create and set upstream + if ! git show-ref --verify --quiet refs/heads/$DEFAULT_BRANCH; then + git checkout -b $DEFAULT_BRANCH origin/$DEFAULT_BRANCH + fi + # Check if an upstream is configured; if not, set it - if ! git rev-parse @{u} > /dev/null 2>&1; then + if ! git rev-parse --abbrev-ref --symbolic-full-name @{u} > /dev/null 2>&1; then git branch --set-upstream-to=origin/$DEFAULT_BRANCH $DEFAULT_BRANCH fi - # Fetch the latest changes + # Fetch the latest changes from the correct branch git fetch origin $DEFAULT_BRANCH > /dev/null 2>&1 # Check if the local repository is behind the remote