Skip to content

Instantly share code, notes, and snippets.

@msis
Created May 31, 2023 14:53
Show Gist options
  • Save msis/4b324292c98a3dade808d8d80338de82 to your computer and use it in GitHub Desktop.
Save msis/4b324292c98a3dade808d8d80338de82 to your computer and use it in GitHub Desktop.
Update org name of local git repos
#!/bin/bash
# variables
old_organization_name="old_organization_name"
new_organization_name="new_organization_name"
parent_dir="$HOME/projects"
# iterate over all directories
for dir in "$parent_dir"/*/
do
dir=${dir%*/} # remove the trailing "/"
cd "$dir" # navigate to directory
# check if it's a git repository
if [ -d .git ]; then
echo "Checking $dir..."
# get current remote URL
remote_url=$(git config --get remote.origin.url)
# check if remote URL contains old organization name
if [[ "$remote_url" == *"$old_organization_name"* ]]; then
# replace old organization name with new one
new_remote_url="${remote_url//$old_organization_name/$new_organization_name}"
# set new remote URL
git remote set-url origin "$new_remote_url"
echo "Updated $dir to use $new_remote_url"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment