自动用镜URL替换URL

发布于 2025-01-21 18:27:30 字数 336 浏览 1 评论 0 原文

由于公司政策,我们无法直接从公司网络访问GitHub,因此必须通过公司镜像完成。当我们需要运行需要从GitHub下载依赖项的代码时,这是非常痛苦的。

现在,我必须进入代码文件,并逐行替换从“ github.com/username/repo_name”到“ company_mirror.com/username/repo_name”的每个URL,其中company_mirror.com是我们的公司镜像。

只是想知道有什么方法可以更改某个地方的设置,以便每当尝试访问github.com时,它都会访问company_mirror.com?这可以通过在BashRC中添加几行来实现吗?

系统:Ubuntu 20.04

Due to company policy we cannot access GitHub directly from company network, it has to be done via a company mirror. This is very painful when we need to run codes that needs to download dependencies from GitHub.

Right now I have to go into the code files and replace line by line for every URL from "github.com/username/repo_name" to "company_mirror.com/username/repo_name" where company_mirror.com is our company mirror.

Just wondering is there a way I can change the setting somewhere so that whenever something tries to access github.com it will access company_mirror.com instead? Could this be achieved by adding a few lines in bashrc?

System: Ubuntu 20.04

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清秋悲枫 2025-01-28 18:27:30

您应该能够添加一个或多个 对您的配置规则:

url。< base> .insteadof

以此值开头的任何URL都将被重写以启动,而使用< base>。如果某些网站提供大量存储库,并使用多种访问方法为其服务,并且某些用户需要使用不同的访问方法,则此功能允许人们指定任何等效的URL,并使GIT自动将URL重写为即使是网站上从未见过的存储库,也是特定用户的最佳选择。当多个字符串匹配给定URL时,使用了最长的匹配。

在此示例中,类似的事情应该起作用:

# Rewrite HTTPS requests to GitHub.com
git config --global url."https://company_mirror.com/".insteadOf "https://github.com/"

# Rewrite SSH requests to GitHub.com
git config --global url."git@company_mirror.com:".insteadOf "[email protected]:"

最终结果将是您的〜/.gitConfig 中的类似结果:

[url "https://company_mirror.com/"]
        insteadOf = "https://github.com/"

[url "git@company_mirror.com:"]
        insteadOf = "[email protected]:"

You should be able to add one or more insteadOf rules to your configuration:

url.<base>.insteadOf

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.

In this example, something like this should work:

# Rewrite HTTPS requests to GitHub.com
git config --global url."https://company_mirror.com/".insteadOf "https://github.com/"

# Rewrite SSH requests to GitHub.com
git config --global url."git@company_mirror.com:".insteadOf "[email protected]:"

And the end result will be something like this in your ~/.gitconfig:

[url "https://company_mirror.com/"]
        insteadOf = "https://github.com/"

[url "git@company_mirror.com:"]
        insteadOf = "[email protected]:"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文