#!/bin/sh branch=$(git symbolic-ref --quiet --short HEAD 2>/dev/null) if [ -z "$branch" ]; then echo "[post-commit] Detached HEAD; skipping auto-push." exit 0 fi if git rev-parse --abbrev-ref --symbolic-full-name "@{upstream}" >/dev/null 2>&1; then echo "[post-commit] Pushing $branch to upstream..." git push push_status=$? else if git remote get-url origin >/dev/null 2>&1; then echo "[post-commit] No upstream configured; pushing $branch to origin..." git push -u origin "$branch" push_status=$? else echo "[post-commit] No upstream or origin remote; skipping auto-push." exit 0 fi fi if [ "$push_status" -ne 0 ]; then echo "[post-commit] Auto-push failed with exit code $push_status. Commit was created locally." fi exit 0