Files
lemke_handClaude Sonnet 5 14b136b0f4
Autodeploy / autodeploy (push) Successful in 9s
Add git-push script to force SSH origin before pushing
Something in this environment periodically rewrites origin back to an
https URL with an embedded token; this script switches it to SSH
before every push so pushes don't depend on that token.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-21 16:25:05 +02:00

29 lines
862 B
Bash
Executable File

#!/bin/bash
# Push the current dir's git repo, forcing the "origin" remote to SSH first.
#
# Some environment automatically rewrites origin back to an https:// URL
# (with an embedded access token) between sessions. Plain `git push` then
# fails or re-auths via that token, so this switches origin to the
# corresponding git@host:path.git SSH URL before pushing.
#
# Any arguments are passed straight through to `git push`.
set -uo pipefail
url="$(git remote get-url origin)" || exit 1
case "$url" in
https://*)
ssh_url="$(echo "$url" | sed -E 's#https://([^/]+)/(.+?)(\.git)?$#git@\1:\2.git#')"
echo "Switching origin: $url -> $ssh_url"
git remote set-url origin "$ssh_url" || exit 1
;;
git@*)
;;
*)
echo "git-push: unrecognized origin URL '$url', leaving as-is" >&2
;;
esac
git push "$@"