#! /usr/bin/env bash # if all subfolders are JS projects with a package.json containing repository.url field # and repository.url is something like "ssh://git@server/project" or "ssh:// REMOTE_PREFIX= for repo in */; do ( cd "$repo" || exit PROJECT_NAME=$(jq -r '.repository.url' package.json | sed -r 's/.*:\/\///' | sed -r 's/[^/]*(.*)\.git/\1/') echo "$PROJECT_NAME" set -x echo git remote set-url origin "$REMOTE_PREFIX$PROJECT_NAME.git" # uncomment this when ready # git remote set-url origin "$REMOTE_PREFIX$PROJECT_NAME.git" set +x ) done;