强制 Window 命令行使用特定的网络适配器

Force Window command line use specific Network Adapter

我有两个网络适配器,每个都连接到不同的网络。 我也有两个 git 存储库,当我将我的提交推送到一个存储库时,类似于

git push -u origin developer

我必须禁用其他网络适配器

有没有办法 运行 git 或者命令行绑定到特定的网络适配器而不需要禁用网络适配器,比如 git remote -v --network 10.1.2.3 ?

由于 Git 本身不支持,如评论所述,您需要使用 netsh command in order to disable/enable a network adapter from command line

你可以在this question or in this script中看到一个例子:

@netsh interface set interface name="LAN1" admin=disabled
@netsh interface set interface name="LAN0" admin=Enabled

这个脚本的想法是检测哪个已启用并禁用它,启用另一个:该脚本将充当一个开关,可以作为 git 别名的一部分调用。