Search code examples
gitnetwork-programmingcommand-linewindow

Force Window command line use specific Network Adapter


I have two network adapters, each connect to different network. I have two git repository too, When I push my commit to one repo, something like

git push -u origin developer

I have to disable other network adapter

enter image description here

Is there a way to run git or command line bind to specific network adapter not need disable network adapter, something like git remote -v --network 10.1.2.3 ?


Solution

  • Since this is not supported by Git itself, as commented, you would need to use the netsh command in order to disable/enable a network adapter from command line

    You can see one example in this question or in this script:

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

    The idea for this script would be to detect which one is enabled and disabling it, enabling the other: the script would act as a switch and could be called as part of a git alias.