Skip to content

Instantly share code, notes, and snippets.

@mahi424
Created October 20, 2023 06:31
Show Gist options
  • Save mahi424/337ca0f840cc0f8a98a051ec83c557a2 to your computer and use it in GitHub Desktop.
Save mahi424/337ca0f840cc0f8a98a051ec83c557a2 to your computer and use it in GitHub Desktop.
if you have moved repos from one account to other. this changes the git origin links to new.
#!/bin/bash
# Prompt the user for the old and new organization names
# read -p "Enter your old organization name: " old_org
# read -p "Enter your new organization name: " new_org
old_org=old_org
new_org=new_org
# Find all git directories recursively from the current directory
repos=$(find . -name ".git" -type d)
# Loop through each git repository and update the origin URL
for repo in $repos; do
# Navigate to the git repository directory
cd "$(dirname "$repo")"
# Get the current origin URL
origin_url=$(git remote get-url origin)
# Replace the old organization name with the new organization name in the origin URL
new_origin_url="${origin_url/$old_org/$new_org}"
# Update th0- e origin URL
git remote set-url origin "$new_origin_url"
# Print a message to indicate that the origin URL has been updated
echo "Updated origin URL for $(pwd) from $origin_url to $new_origin_url"
# Navigate back to the starting directory
cd - >/dev/null
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment