add script for updating the remote urls

This commit is contained in:
2023-07-26 21:39:17 -06:00
parent 37aa4e3899
commit 87e5f80adb

34
update_git_remotes.sh Normal file
View File

@ -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