Skip to content

Instantly share code, notes, and snippets.

@oscarmorrison
Created January 4, 2019 04:35
Show Gist options
  • Select an option

  • Save oscarmorrison/01bcc312d91315d0af281c9e3d0f8c37 to your computer and use it in GitHub Desktop.

Select an option

Save oscarmorrison/01bcc312d91315d0af281c9e3d0f8c37 to your computer and use it in GitHub Desktop.

Revisions

  1. oscarmorrison created this gist Jan 4, 2019.
    22 changes: 22 additions & 0 deletions switchGitProtocol.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    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="[email protected]:$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