#/bin/bash #Just put this script in the root folder and run it for d in *; do if [ -d "$d" ]; then echo $d cd $d REPO_URL=`git remote -v | grep -m1 '^origin' | sed -Ene's#.*(https://[^[:space:]]*).*#\1#p'` if [ -z "$REPO_URL" ]; then echo "-- ERROR: Could not identify Repo url." echo " It is possible this repo is already using SSH instead of HTTPS." cd .. continue fi REPO_URL="${REPO_URL/.git/}" echo $REPO_URL USER=`echo $REPO_URL | sed -Ene's#https://github.com/([^/]*)/(.*)#\1#p'` if [ -z "$USER" ]; then echo "-- ERROR: Could not identify User." cd .. continue fi echo $USER REPO=`echo $REPO_URL | sed -Ene's#https://github.com/([^/]*)/(.*)#\2#p'` if [ -z "$REPO" ]; then echo "-- ERROR: Could not identify Repo." cd .. continue fi NEW_URL="git@github.com:$USER/$REPO.git" echo "Changing repo url from " echo " '$REPO_URL'" echo " to " echo " '$NEW_URL'" echo "" CHANGE_CMD="git remote set-url origin $NEW_URL" `$CHANGE_CMD` echo "Success" cd ../ fi done