supporting roaming via git URL rewriting

Adam Spiers vcs-home at adamspiers.org
Thu Dec 22 16:16:44 CET 2011


I have some laptops with git(-annex) repositories on them.  These are
sometimes connected via wifi, other times via a cable, and obtain
different IP addresses via DHCP depending on which is used.  In the
corresponding repositories on my static desktop machine, previously I
used to deal with this by having two remotes for each laptop, e.g.
for my laptop called "southern":

  southern-wired       ssh://southern-wired/home/adam/media (fetch)
  southern-wired       ssh://southern-wired/home/adam/media (push)
  southern-wifi        ssh://southern-wifi/home/adam/media (fetch)
  southern-wifi        ssh://southern-wifi/home/adam/media (push)

However, if you do a git fetch from or push to southern-wired while
plugged in, and then later switch to wifi, the remote branch refs for
southern-wifi still need to be updated separately.

Here's another situation in which this inconvenience is more
pronounced: my main desktop machine "atlantic" is reachable both via
the LAN and via the internet (using port forwarding from my public
static IP).  So if I'm on a laptop and pull from it via the LAN, and
then later leave the LAN and want to pull from or push to it again via
ADSL, there's more work to be done.

However I just discovered git's URL rewriting feature, which solves
this by allowing an extra layer of indirection.  I wrote this utility:

  https://github.com/aspiers/git-config/blob/master/bin/git-url-rewrite

Now I can configure a single remote pointing to my desktop machine,
with URL "atlantic:path/to/repo".  When I leave the house, I run:

  git url-rewrite atlantic: ssh://public.adamspiers.org/home/adam/

and when I get back:

  git url-rewrite atlantic: ssh://atlantic/home/adam/

I guess I could even automate this.

Hope that's of use or interest to somebody.


More information about the vcs-home mailing list