Last active
December 22, 2020 06:18
-
-
Save nyrahul/0dd05f6379c993d8089b66f3ab7f0461 to your computer and use it in GitHub Desktop.
Switch all the remotes from https to 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
#!/bin/bash | |
# Switch all the remotes from https to git | |
# e.g, https://github.com/username/reponame.git -> [email protected]:username/reponame.git | |
switch4remote() | |
{ | |
url=`git remote get-url $1` | |
[[ ! $url =~ ^https ]] && echo "Remote [$1] might be on git already" && return 0 | |
path=`echo $url | sed -Ene 's#https://github.com/(.*)#\1#p'` | |
[[ "$path" == "" ]] && echo "couldnot identify the path! URL:$url" && return 1 | |
cmd="git remote set-url $1 [email protected]:$path" | |
echo "$cmd" | |
$cmd | |
} | |
# for all remotes: origin, upstream, ... | |
for remote in `git remote -v | awk '{ print $1 }' | uniq`; do | |
switch4remote $remote | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment