#!/bin/bash # Old and new usernames old_username="root" new_username="git" # Directory containing your Git repositories src_directory="/c/Users/gomas/src" # Loop through all the directories inside 'src_directory' for repo_dir in "$src_directory"/*/; do # Check if it's a Git repository (has a .git directory) if [ -d "$repo_dir/.git" ]; then # Change into the repository directory cd "$repo_dir" || continue # Get the remote URL for the 'origin' remote old_url=$(git remote get-url origin) # Check if the old username is in the remote URL if [[ $old_url == *"$old_username"* ]]; then # Replace the old username with the new username in the remote URL new_url=$(echo "$old_url" | sed "s/$old_username/$new_username/g") # Update the remote URL for the 'origin' remote git remote set-url origin "$new_url" # Print the update for this repository echo "Updated remote URL for $repo_dir:" echo " Old URL: $old_url" echo " New URL: $new_url" fi fi done