fix: git remote switch script error

This commit is contained in:
janishutz committed 2026-10-05 18:15:31 +02:00
1 parent 5764b73e5c
commit 7aef30d600
1 file changed
+4 -4
+4 -4
View File
@@ -4,18 +4,18 @@ set -e
origin=$(git remote get-url origin)
if [[ $(echo "$origin" | awk -e '/https/') != "" ]]; then
git_url="git@$(echo "$origin" | cut -d "/" -f 3):/$($(echo "$origin" | cut -d "/" -f 4-))"
git_url="git@$(echo "$origin" | cut -d "/" -f 3):/$(echo "$origin" | cut -d "/" -f 4-)"
else
git_url="https://$(echo "$origin" | cut -d "@" -f 2 | cut -d ":" -f 1)/$(echo "$origin" | cut -d ":" -f 2 | cut -d "/" -f 2-)"
fi
git_branches=$(git branch | grep '*' | tr -d ' *')
git remote remove origin
git remote add origin $git_url
git remote add origin "$git_url"
git fetch
echo "New git url $git_url, updating branches"
for branch in $git_branches; do
git checkout $branch
git branch --set-upstream-to=origin/$branch $branch
git checkout "$branch"
git branch --set-upstream-to=origin/$branch "$branch"
echo "Branch $branch configured to track on origin/$branch"
done