I basically work from home or from my company office accessing git repos available on my company network or elsewhere (personnal gitlab repos, github...). I usually use the same laptop for all locations.
When I'm working from office I can ssh to my local company repos but I can't ssh out of the network. I have setup the following relevant config snip in my .gitconfig
so that the repos cloned from home are still accessible:
[url "ssh://git@comp.any.co/"]
insteadof = https://comp.any.co/
[url "https://pers.onal.co/]
insteadof = ssh://git@pers.onal.co:1234/
[url "https://github.com/"]
insteadof = ssh://git@github.com/
When I work remotely from home, I cannot ssh to my company repos anymore but I can use ssh elsewhere. In this case I need to change my configuration snippet to:
[url "https://comp.any.co/"]
insteadof = ssh://git@comp.any.co/
[url "ssh://git@pers.onal.co:1234/]
insteadof = https://pers.onal.co/
[url "ssh://git@github.com/"]
insteadof = https://github.com/
I could actually force https for every repo from every location. Although this would not make much difference for personal and github repos, there are some specificity on the company network that make this protocol switch highly preferred.
I'm looking for a way to automate this config switch based on network location (e.g. ip subnet, proxy availability...). I've looked at include.path
and includeif.path
but neither will let me execute a script or check for e.g. an environment variable.
I see a possible workaround with includeif.path
and playing with the path from which I access my repos on my laptop depending on my physical location. But that is not really an automation and really far from ideal.
Before I go back writing a script or a shell function to automate this outside of git, did I miss any power usage of git config that would actually fulfill my requirement?