aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/swap-protocol.bash
blob: 91be97709a40ed3237e47da32bcb93ed9f9ea944 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#! /usr/bin/env bash

target=''
extra=''

# For each remote
git remote -v \
| while read remote url etc; do
  [[ $etc =~ push ]] && extra='--push' || extra=''
  if [[ $url =~ git@.*github.com ]]; then
    target=${target:-https}
    [[ $target == https ]] && sed -E 's#^git@(.+):(.+)$#https://\1/\2#' <<<$url | xargs git remote set-url $extra $remote
  elif [[ $url =~ https://.*github.com ]]; then
    target=${target:-git}
    [[ $target == git ]] && sed -E 's#^https://([^/]+)/(.+)$#git@\1:\2#' <<<$url | xargs git remote set-url $extra $remote
  fi
done

git remote -v