feat: script to change git remote type between ssh and https
This commit is contained in:
1 parent
f4388ad430
commit
a8439f1033
1 file changed
+24
Executable
+24
@@ -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
|
||||
Reference in new issue
Block a user