From 586bcca9d859d3444b17c01dc3c04be7f3e4a8f4 Mon Sep 17 00:00:00 2001 From: Janis Hutz Date: Mon, 5 Oct 2026 17:24:54 +0200 Subject: [PATCH] feat: git remote change script doesn't need originial auth method --- scripts/git-switch-remote-type | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/scripts/git-switch-remote-type b/scripts/git-switch-remote-type index fab6e1d..f4133ab 100755 --- a/scripts/git-switch-remote-type +++ b/scripts/git-switch-remote-type @@ -2,22 +2,19 @@ set -e -origin=$(git remote show origin) +origin=$(git remote get-url origin) +git_branch=$(git branch | grep '*' | tr -d ' *') if [[ $(echo "$origin" | awk -e '/https/') != "" ]]; then - remote=$(git remote show origin | awk -e '/Fetch/' | cut -d ":" -f 3) - git_host=$(echo "$remote" | cut -d "/" -f 3) - git_repo=$(echo "$remote" | cut -d "/" -f 4-) - git_branch=$(echo "$origin" | awk -e '/HEAD/' | cut -d ":" -f 2 | tr -d ' ') + git_host=$(echo "$origin" | cut -d "/" -f 3) + git_repo=$(echo "$origin" | cut -d "/" -f 4-) git remote remove origin git remote add origin git@$git_host:/$git_repo git fetch git branch --set-upstream-to=origin/$git_branch $git_branch echo "Updated to SSH url git@$git_host:/$git_repo, for branch $git_branch" else - remote=$(git remote show origin | awk -e '/Fetch/' | cut -d ":" -f 2-3) - git_host=$(echo "$remote" | cut -d "@" -f 2 | cut -d ":" -f 1) - git_repo=$(echo "$remote" | cut -d ":" -f 2 | cut -d "/" -f 2-) - git_branch=$(echo "$origin" | awk -e '/HEAD/' | cut -d ":" -f 2 | tr -d ' ') + git_host=$(echo "$origin" | cut -d "@" -f 2 | cut -d ":" -f 1) + git_repo=$(echo "$origin" | cut -d ":" -f 2 | cut -d "/" -f 2-) git remote remove origin git remote add origin https://$git_host/$git_repo git fetch