-
First cd to the directory where all of your sites are located
$ cd /srv/sites -
Change all previous urls from
url = git@old-server.example.com:foo.gittourl = git@cod.example.com:foo.git$ cwd=`pwd`; for d in *; do if [[ -e "$cwd/$d/.git/config" ]]; then echo "$cwd/$d/.git/config" | xargs perl -i.bak -wpe 's|(url = git\@old-server(\.example\.com)?):([-_a-z]+)\.git|url = git\@new-server.example.com:$3.git|g'; fi; done -
Check to see if the change worked
$ cwd=`pwd`; for d in *; do if [[ -e "$cwd/$d/.git/config" ]]; then cat "$cwd/$d/.git/config" | grep url; fi; done -
If the change worked then you can remove the backup files
$ cwd=`pwd`; for d in *; do if [[ -e "$cwd/$d/.git/config.bak" ]]; then rm "$cwd/$d/.git/config.bak"; fi; done -
If the change didn't work you can run the following to restore the original config. After restoring the original config go back to step 2 and change the perl search and replace so it works.
$ cwd=`pwd`; for d in *; do if [[ -e "$cwd/$d/.git/config.bak" ]]; then cp "$cwd/$d/.git/config.bak" "$cwd/$d/.git/config" | grep url; fi; done
Created
May 17, 2012 18:27
-
-
Save epicserve/2720771 to your computer and use it in GitHub Desktop.
How to change your remote origin URL for all your Git repositories
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment