为所有本地存储库更改 Git URL
Changing Git URL for all local repositories
最近,我们迁移了 Stash Git 服务器以使用 HTTPS 而不是 HTTP。现在我们必须更新每个存储库中的 URL 以使用新的 URL 和 HTTPS。有什么方法可以在不转到每个存储库的 Git 配置并更改 URL 的情况下实现这一点?问题是我们有近 60 个本地存储库需要更新。
非常感谢任何一次性更新 URL 的解决方案。
您可以使用 sed
,但要小心 ;)
sed -i 's/git.oldserver.com/git.newserver.com/' /path/to/repos/*/.git/config
这将进行内联字符串替换,用新字符串替换旧字符串。您只需要将所有 git 配置文件的路径传递给它。
每个开发者都可以全局配置 url.<base>.insteadOf
设置:
git config --global url."https://your-domain".insteadOf http://your-domain
This will cause 以 http://your-domain
开头的 URL 将被动态重写为以 https://your-domain
:
开头
Any URL that starts with this value will be rewritten to start, instead, with <base>
. In cases where some site serves a large number of repositories, and serves them with multiple access methods, and some users need to use different access methods, this feature allows people to specify any of the equivalent URLs and have Git automatically rewrite the URL to the best alternative for the particular user, even for a never-before-seen repository on the site. When more than one insteadOf strings match a given URL, the longest match is used.
最近,我们迁移了 Stash Git 服务器以使用 HTTPS 而不是 HTTP。现在我们必须更新每个存储库中的 URL 以使用新的 URL 和 HTTPS。有什么方法可以在不转到每个存储库的 Git 配置并更改 URL 的情况下实现这一点?问题是我们有近 60 个本地存储库需要更新。
非常感谢任何一次性更新 URL 的解决方案。
您可以使用 sed
,但要小心 ;)
sed -i 's/git.oldserver.com/git.newserver.com/' /path/to/repos/*/.git/config
这将进行内联字符串替换,用新字符串替换旧字符串。您只需要将所有 git 配置文件的路径传递给它。
每个开发者都可以全局配置 url.<base>.insteadOf
设置:
git config --global url."https://your-domain".insteadOf http://your-domain
This will cause 以 http://your-domain
开头的 URL 将被动态重写为以 https://your-domain
:
Any URL that starts with this value will be rewritten to start, instead, with
<base>
. In cases where some site serves a large number of repositories, and serves them with multiple access methods, and some users need to use different access methods, this feature allows people to specify any of the equivalent URLs and have Git automatically rewrite the URL to the best alternative for the particular user, even for a never-before-seen repository on the site. When more than one insteadOf strings match a given URL, the longest match is used.