Created
November 20, 2018 14:48
-
-
Save vahanNasibyan/5d030ea66c53d07018b2d239af812c4a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/bin/bash | |
#origin or upstream | |
REMOTE=${1-origin} | |
REPO_URL=`git remote -v | grep -m1 "^$REMOTE" | sed -Ene's#.*([email protected]:[^[:space:]]*).*#\1#p'` | |
if [ -z "$REPO_URL" ]; then | |
echo "-- ERROR: Could not identify Repo url." | |
echo " It is possible this repo is already using HTTPS instead of SSH." | |
exit | |
fi | |
USER=`echo $REPO_URL | sed -Ene's#[email protected]:([^/]*)/(.*).git#\1#p'` | |
if [ -z "$USER" ]; then | |
echo "-- ERROR: Could not identify User." | |
exit | |
fi | |
REPO=`echo $REPO_URL | sed -Ene's#[email protected]:([^/]*)/(.*).git#\2#p'` | |
if [ -z "$REPO" ]; then | |
echo "-- ERROR: Could not identify Repo." | |
exit | |
fi | |
#NEW_URL="[email protected]:$USER/$REPO.git" | |
NEW_URL="https://bitbucket.org/$USER/$REPO.git" | |
echo "Changing repo url from " | |
echo " '$REPO_URL'" | |
echo " to " | |
echo " '$NEW_URL'" | |
echo "" | |
CHANGE_CMD="git remote set-url $REMOTE $NEW_URL" | |
echo "$CHANGE_CMD" | |
`$CHANGE_CMD` | |
echo "Success" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment