diff options
Diffstat (limited to 'bin/git/swap-protocol.bash')
-rwxr-xr-x | bin/git/swap-protocol.bash | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/bin/git/swap-protocol.bash b/bin/git/swap-protocol.bash new file mode 100755 index 0000000..b7f4db2 --- /dev/null +++ b/bin/git/swap-protocol.bash | |||
@@ -0,0 +1,25 @@ | |||
1 | #! /usr/bin/env bash | ||
2 | # Get the first remote URL within git/https protocol on github.com | ||
3 | # Swap the protocol, and apply new protocol to every remaining remotes | ||
4 | |||
5 | target='' | ||
6 | extra='' | ||
7 | |||
8 | # For each remote | ||
9 | git remote -v \ | ||
10 | | while read remote url etc; do | ||
11 | # Set fetch/push URL seperately | ||
12 | [[ $etc =~ push ]] && extra='--push' || extra='' | ||
13 | |||
14 | if [[ $url =~ git@.*github.com ]]; then | ||
15 | target=${target:-https} | ||
16 | # git@ -> https:// | ||
17 | [[ $target == https ]] && sed -E 's#^git@(.+):(.+)$#https://\1/\2#' <<<$url | xargs git remote set-url $extra $remote | ||
18 | elif [[ $url =~ https://.*github.com ]]; then | ||
19 | target=${target:-git} | ||
20 | # https:// -> git@ | ||
21 | [[ $target == git ]] && sed -E 's#^https://([^/]+)/(.+)$#git@\1:\2#' <<<$url | xargs git remote set-url $extra $remote | ||
22 | fi | ||
23 | done | ||
24 | |||
25 | git remote -v | ||