From 87e5f80adb251b407c7b60068f5c7dae9e809159 Mon Sep 17 00:00:00 2001 From: Mason Payne Date: Wed, 26 Jul 2023 21:39:17 -0600 Subject: [PATCH] add script for updating the remote urls --- update_git_remotes.sh | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 update_git_remotes.sh diff --git a/update_git_remotes.sh b/update_git_remotes.sh new file mode 100644 index 0000000..5dde2de --- /dev/null +++ b/update_git_remotes.sh @@ -0,0 +1,34 @@ +#!/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