this repo has no description
1#!/bin/bash
2#-- Script to automatically convert all git remotes to SSH from HTTPS
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
9http_to_ssh(){
10 echo ""
11 echo "Checking for $1..."
12
13 REPO_URL=`git remote -v | grep -m1 "^$1" | sed -Ene's#.*(https://[^[:space:]]*).*#\1#p'`
14 if [ -z "$REPO_URL" ]; then
15 if [ "$1" == "upstream" ]; then
16 echo "-- No upstream found"
17 exit
18 else
19 echo "-- ERROR: Could not identify Repo url."
20 echo " It is possible this repo is already using SSH instead of HTTPS."
21 exit
22 fi
23 fi
24
25 USER=`echo $REPO_URL | sed -Ene's#https://github.com/([^/]*)/(.*)#\1#p'`
26 if [ -z "$USER" ]; then
27 echo "-- ERROR: Could not identify User."
28 exit
29 fi
30
31 REPO=`echo $REPO_URL | sed -Ene's#https://github.com/([^/]*)/(.*)#\2#p'`
32 if [ -z "$REPO" ]; then
33 echo "-- ERROR: Could not identify Repo."
34 exit
35 fi
36
37 NEW_URL="git@github.com:$USER/${REPO%.git}.git"
38 echo "Changing repo url from "
39 echo " '$REPO_URL'"
40 echo " to "
41 echo " '$NEW_URL'"
42 echo ""
43
44 CHANGE_CMD="git remote set-url $1 $NEW_URL"
45 echo "$CHANGE_CMD"
46 `$CHANGE_CMD`
47}
48
49for i in `git remote`; do
50 http_to_ssh "$i"
51done;
52
53echo "Moved everything to SSH!"