Last Updated: February 25, 2016
· jabbrwcky
Gopher jha gray

Replace remote URL for multiple git repositories

Th Github client application from github.com is quite nice - if it only would not insist on using the read-only HTTPS repository URL as the origin URL.

Changing it via the application or via git set remote is painful if more than a handful of repositories have to be changed.

Here is a quick way to achieve the effect:

sed -E -e "s/https:\/\/(github.com)\/(.+)/git@\1:\2/g" -i .old `find `pwd`/*/.git -name config -print`

For fish or similar shells:

sed -E -e "s/https:\/\/(github.com)\/(.+)/git@\1:\2/g" -i .old (find (pwd)/*/.git -name config -print)

Saves a backup copy config.old in .git, omit ".old" after -i to prevent creation of a backup.

For a single repo it works quite the same:

sed -E -e "s/https:\/\/(github.com)\/(.+)/git@\1:\2/g" -i .old .git/config
Say Thanks
Filed Under