-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttps_origin.sh
40 lines (33 loc) · 1.06 KB
/
https_origin.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#/bin/bash
#-- Script to automate https://help.github.com/articles/why-is-git-always-asking-for-my-password
REPO_URL=`git remote -v | grep -m1 '^origin' | sed -Ene's#.*(git@[^[: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."
exit
fi
HOST=`echo $REPO_URL | sed -Ene's#git@([^:]*):([^/]*)/([^\.]*)(\.git){0,1}#\1#p'`
USER=`echo $REPO_URL | sed -Ene's#git@([^:]*):([^/]*)/([^\.]*)(\.git){0,1}#\2#p'`
REPO=`echo $REPO_URL | sed -Ene's#git@([^:]*):([^/]*)/([^\.]*)(\.git){0,1}#\3#p'`
if [ -z "$USER" ]; then
echo "-- ERROR: Could not identify User."
exit
fi
if [ -z "$REPO" ]; then
echo "-- ERROR: Could not identify Repo."
exit
fi
if [ -z "$HOST" ]; then
echo "-- ERROR: Could not identify Host."
exit
fi
NEW_URL="https://$HOST/$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"
echo "$CHANGE_CMD"
`$CHANGE_CMD`
echo "Success"