From 8895255af2414fff3ab60f086adb36a892b985a1 Mon Sep 17 00:00:00 2001 From: Mark Randall Havens Date: Fri, 30 May 2025 05:31:33 -0500 Subject: [PATCH] Update: 2025-05-30 05:31:33 --- github/gitlink-github.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/github/gitlink-github.sh b/github/gitlink-github.sh index 3104fe8..ff0d0bf 100755 --- a/github/gitlink-github.sh +++ b/github/gitlink-github.sh @@ -110,11 +110,18 @@ else fi # ──────────────── -# Push If Branch Is Ahead +# Push and Auto-Set Upstream If Needed # ──────────────── -if git status | grep -q "Your branch is ahead"; then - info "Pushing to GitHub..." - git push "$GIT_REMOTE_NAME" "$(git rev-parse --abbrev-ref HEAD)" || error "Push failed" +BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) + +if git status 2>&1 | grep -q "no upstream"; then + info "Setting upstream for '$BRANCH_NAME' to '$GIT_REMOTE_NAME'..." + git push -u "$GIT_REMOTE_NAME" "$BRANCH_NAME" || error "Failed to push and set upstream" else - info "No push needed. Everything is up to date." + if git status | grep -q "Your branch is ahead"; then + info "Pushing to GitHub..." + git push "$GIT_REMOTE_NAME" "$BRANCH_NAME" || error "Push failed" + else + info "No push needed. Everything is up to date." + fi fi