From a8439f10338b9c4a690ba7bb33fb98cbf7622465 Mon Sep 17 00:00:00 2001 From: Janis Hutz Date: Sun, 4 Oct 2026 11:59:15 +0200 Subject: [PATCH] feat: script to change git remote type between ssh and https --- scripts/change-git-remote | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 scripts/change-git-remote diff --git a/scripts/change-git-remote b/scripts/change-git-remote new file mode 100755 index 0000000..6cef4ee --- /dev/null +++ b/scripts/change-git-remote @@ -0,0 +1,24 @@ +#!/bin/bash + +origin=$(git remote show origin) +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-5) + git_branch=$(echo "$origin" | awk -e '/HEAD/' | cut -d ":" -f 2 | tr -d ' ') + 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 remote remove origin + git remote add origin https://$git_host/$git_repo + git fetch + git branch --set-upstream-to=origin/$git_branch $git_branch + echo "Updated to HTTPS url https://$git_host/$git_repo, for branch $git_branch" +fi