Skip to content

Instantly share code, notes, and snippets.

@stekhn
Last active April 3, 2018 10:03
Show Gist options
  • Select an option

  • Save stekhn/859a77240d92ebd391fd91469bdab3e3 to your computer and use it in GitHub Desktop.

Select an option

Save stekhn/859a77240d92ebd391fd91469bdab3e3 to your computer and use it in GitHub Desktop.
Change Git remote url for all directories in path. Useful, if you have migrated multiple repositories to a new organisation or user.
#!/bin/bash
# Change Git remote url for all directories in current path
old_org="git@github.com:old-organisation"
new_org="git@github.com:new-organisation"
for d in ./*; do
echo "$d"
if [ -d "$d" ]; then
cd "$d"
remote_url="$(git config --get remote.origin.url)"
if [[ "$remote_url" = *"$old_org"* ]]; then
new_remote_url=${remote_url/$old_org/$new_org}
git remote set-url origin "$new_remote_url"
echo "$new_remote_url"
fi
cd ..
fi
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment