-
-
Save dammyammy/25165485b1beec665c7941eebe8fb9e1 to your computer and use it in GitHub Desktop.
Convert BitBucket HTTPS to SSH
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 | |
| #-- Author: Bhagya Silva (https://about.me/bhagyas) | |
| #-- Script to automate https://help.github.com/articles/why-is-git-always-asking-for-my-password | |
| #-- based on original code from : https://gist.github.com/m14t/3056747 | |
| 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." | |
| exit | |
| fi | |
| USER=`echo $REPO_URL | sed -Ene's#https://(.*)@bitbucket.org/([^/]*)/(.*).git#\2#p'` | |
| if [ -z "$USER" ]; then | |
| echo "-- ERROR: Could not identify User." | |
| exit | |
| fi | |
| echo "USER: ${USER}" | |
| REPO=`echo $REPO_URL | sed -Ene's#https://(.*)@bitbucket.org/([^/]*)/(.*).git#\3#p'` | |
| if [ -z "$REPO" ]; then | |
| echo "-- ERROR: Could not identify Repo." | |
| exit | |
| fi | |
| echo "REPO: ${REPO}" | |
| NEW_URL="[email protected]:$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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment