#!/bin/env bash OLD_DOMAIN="git.ficd.sh" NEW_DOMAIN="g0.ficd.sh" PORT="59681" SEARCH_DIR="${1:-$PWD}" find "$SEARCH_DIR" -type d -name ".git" | while read -r gitdir; do repo_dir="$(dirname "$gitdir")" cd "$repo_dir" || exit 1 if ! git rev-parse --is-inside-work-tree &>/dev/null; then continue fi # get current url current_url=$(git remote get-url origin) # match scp style if [[ "$current_url" =~ ^git@${OLD_DOMAIN}:(.*) ]]; then path="${BASH_REMATCH[1]}" new_url="ssh://git@${NEW_DOMAIN}:${PORT}/${path}" # match ssh:// elif [[ "$current_url" =~ ^ssh://git@${OLD_DOMAIN}(:[0-9]+)?/(.*) ]]; then path="${BASH_REMATCH[2]}" new_url="ssh://git@${NEW_DOMAIN}:${PORT}/${path}" else continue fi echo "Updating $repo_dir" echo " Old: $current_url" echo " New: $new_url" git remote set-url origin "$new_url" done