Letting the user choose a git clone protocol

I am trying to use FetchContent to replace git submodules pointing to other local projects. One problem I have is that the protocol provided to FetchContent is fixed and forced to the user. For example, If I provide a SSH link to a subproject, a colleague that has not set her SSH keys will hit an error during configuration. I do not have this issue with submodules.

Is there a known pattern to solve this problem?

You could provide an option which switches the protocol. Alternatively, you can use the insteadOf feature of Git. Here’s a blog post about it. Basically, you set the URL as someprefix:path/to/repo.git and tell Git that a prefix of someprefix: should be replaced by https://some.hosting.service/ or ssh://git@some.hosting.service/ depending on local configuration.

1 Like