使用每个分支的单个命令推送到具有不同代理的多个远程

Pushing to multiple remotes with different proxies with single command for each branch

我想为每个分支做 git push,它会推送到我的 2 个遥控器(每个分支有不同的遥控器)。

我确实为每个分支都试过了:

git remote set-url --add --push all repo1
git remote set-url --add --push all repo2
git branch --set-upstream-to=all/master

这应该可以,但我的代理有问题。 repo1 在内联网中我的 GitLab 存储库中,不使用代理,但 repo2 在 Azure 中,需要代理。因此 git push 失败。

如何在同一个遥控器中使用不同的 url 代理?或者也许还有其他一些想法可以解决这个要求?

最简单的方法是编写 2 个批处理文件,一个用于设置代理,一个用于取消设置代理并进行管理。

您可以在 git bash 中使用以下命令设置 Git 代理。为 HTTP 和 HTTPS 代理设置。

git config --global http.proxy http://username:password@proxy.server.com:8080
git config --global https.proxy http://username:password@proxy.server.com:8080

//Replace username with your proxy username
//Replace password with your proxy password
//Replace proxy.server.com with the proxy domain URL.
//Replace 8080 with the proxy port no configured on the proxy server.

要取消设置 Git 代理,请使用以下命令

git config --global --unset http.proxy
git config --global --unset https.proxy

查看我在 How to configure Git proxy and How to unset the Git Proxy 上的博客了解更多详情