Skip to content

Instantly share code, notes, and snippets.

@oscarmorrison
Created January 4, 2019 04:35
Show Gist options
  • Save oscarmorrison/01bcc312d91315d0af281c9e3d0f8c37 to your computer and use it in GitHub Desktop.
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
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