Skip to content

Instantly share code, notes, and snippets.

@dhaiducek
Last active January 5, 2022 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhaiducek/3f4f87f3d31d5c5612ad0a7910466224 to your computer and use it in GitHub Desktop.
Save dhaiducek/3f4f87f3d31d5c5612ad0a7910466224 to your computer and use it in GitHub Desktop.
Recursively update local Git URLs for new organization name from current directory
#! /bin/bash
# Export or update OLD_ORG and NEW_ORG to match the old and new organization names in Git
OLD_ORG=${OLD_ORG:-"<old-org-name>"}
NEW_ORG=${NEW_ORG:"<new-org-name>"}
for REPO in $(find ${PWD} -type d -name .git 2>/dev/null); do
cd ${REPO}
if git remote -v | grep /${OLD_ORG}/ &>/dev/null; then
echo "* Processing: ${REPO}"
REMOTE_NAME=$(git remote -v | awk '/\/'${OLD_ORG}'\// {print $1}' | head -1)
REMOTE_URL=$(git remote -v | awk '/\/'${OLD_ORG}'\// {gsub('"${OLD_ORG}"', '"${NEW_ORG}"'); print $2}' | head -1)
git remote set-url ${REMOTE_NAME} ${REMOTE_URL}
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment