Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I attach multiple urls to a single git remote?

Tags:

git

I'm currently using git on windows through a combination of msysgit and Cygwin.

I have a laptop which I move around quite a bit, so it's not on a consistent location. Unfortunately, I don't have a consistent name for it due to the computer name not being resolved on all of the locations I connect to, so I can't just use the computer name as the host for the url (e.g. git://compname/repo), so I have to use the IP address.

Is there a way I can add multiple urls to pull from for a particular remote? I've seen

git remote set-url --add [--push] <name> <newurl>

as a way to add multiple URLs to a remote, and I can see the updates in the .git/config file, but git only tries to use the first one.

Is there a way to get git to try to use all of the urls? I've tried both git fetch and git remote update, but neither tries anything after the first url.

Note that I haven't tried this on linux yet, and I can't fix the computer name resolution as this is at work.

like image 295
deterb Avatar asked Apr 15 '10 21:04

deterb


1 Answers

I think your best best is to set your remote URI to point to computername but then add computername to your hosts file (located at %SystemRoot%\system32\drivers\etc\hosts):

computername    192.168.100.34
# computername    192.168.100.68

Then you can keep multiple entries for the different IP addresses and comment / uncomment them as needed. No more messing about changing the remote URI on a per-repo basis, just update in one place and then all repos using computername as the URI will use the new location.

like image 91
Mark Stickley Avatar answered Sep 28 '22 08:09

Mark Stickley