Created
January 18, 2022 17:28
-
-
Save monkpit/8959b3d9e2bfd89cd1dd0b788912c81c to your computer and use it in GitHub Desktop.
Change git remote in all subdirectories
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
#! /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=<your git server prefix like git@server> | |
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment