Created
January 4, 2019 04:35
-
-
Save oscarmorrison/01bcc312d91315d0af281c9e3d0f8c37 to your computer and use it in GitHub Desktop.
A quick bash script to change a repo from ssh to https and vice versa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo "Opening git repo" | |
giturl=$(git config --get remote.origin.url) | |
giturl=$( tr '[A-Z]' '[a-z]' <<< $giturl) | |
if [[ $giturl == *"https"* ]] | |
then | |
echo "Switching repo remote origin url from HTTPS to SSH" | |
echo $giturl | |
giturl=${giturl#https://github.com/} | |
repo=${giturl/\.git} | |
repo="git@github.com:$repo.git" | |
git remote set-url origin $repo | |
git remote -v | |
else | |
echo "Switching repo remote origin url from SSH to HTTPS" | |
echo $giturl | |
giturl=${giturl#git@github.com:} | |
repo=${giturl/\.git} | |
repo="https://github.com/$repo.git" | |
git remote set-url origin $repo | |
git remote -v | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment