Last active
April 3, 2018 10:03
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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