this repo has no description
1#!/bin/bash
2#-- Script to automatically convert all git remotes to HTTPS from SSH
3# Script will change all the git remotes.
4# If you didn't intend to do that, run the other script in this repo.
5# Original 1: https://gist.github.com/m14t/3056747
6# Original 2: https://gist.github.com/chuckbjones/9dc6634fe52e56ba45ac
7# Thanks to @m14t, @michaelsilver and @chuckbjones.
8
9ssh_to_https(){
10 REPO_URL=`git remote -v | grep -m1 "^$1" | sed -Ene's#.*(git@github.com:[^[:space:]]*).*#\1#p'`
11 if [ -z "$REPO_URL" ]; then
12 echo "-- ERROR: Could not identify Repo url."
13 echo " It is possible this repo is already using HTTPS instead of SSH."
14 exit
15 fi
16
17 USER=`echo $REPO_URL | sed -Ene's#git@github.com:([^/]*)/(.*).git#\1#p'`
18 if [ -z "$USER" ]; then
19 echo "-- ERROR: Could not identify User."
20 exit
21 fi
22
23 REPO=`echo $REPO_URL | sed -Ene's#git@github.com:([^/]*)/(.*).git#\2#p'`
24 if [ -z "$REPO" ]; then
25 echo "-- ERROR: Could not identify Repo."
26 exit
27 fi
28
29 #NEW_URL="git@github.com:$USER/$REPO.git"
30 NEW_URL="https://github.com/$USER/$REPO.git"
31 echo "Changing repo url from "
32 echo " '$REPO_URL'"
33 echo " to "
34 echo " '$NEW_URL'"
35 echo ""
36
37 CHANGE_CMD="git remote set-url $1 $NEW_URL"
38 echo "$CHANGE_CMD"
39 `$CHANGE_CMD`
40}
41
42for i in `git remote`; do
43 ssh_to_https "$i";
44done;
45
46echo "Moved everything to HTTPS!"