Created
December 21, 2017 09:11
-
-
Save yogeek/db04dc59675c2b7f94b78e7818121ee4 to your computer and use it in GitHub Desktop.
GIT
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
| # Script to switch between HTTP and SSH git remote URL | |
| gitswitch () { | |
| if [[ "$(git remote -v)" == "" ]] | |
| then | |
| echo "No remote configured. Use 'git remote add' to set one" | |
| return | |
| fi | |
| remoteRoot=$(git remote -v | head -1 | grep root) | |
| if [[ "$remoteRoot" == "" ]] | |
| then | |
| echo "git switching : https -> ssh" | |
| repo=$(git remote -v | head -1 | sed -Ene's#.*https://([^[:space:]|/]*)/([^[:space:]]*).*#\1:\2#p') | |
| prefix="root@" | |
| else | |
| echo "git switching : ssh -> https" | |
| repo=$(git remote -v | head -1 | sed -Ene's#.*root@([^[:space:]]*):([^[:space:]]*).*#\1/\2#p') | |
| prefix="https://" | |
| fi | |
| git remote set-url origin $prefix$repo | |
| git remote -v | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment