Home > Enterprise >  git config insteadOf for https://host/project/<project>/repo/<repo>
git config insteadOf for https://host/project/<project>/repo/<repo>

Time:01-29

git config <url>.insteadOf <url> is working flawlessly and easy for simple URL schemes like GitHub or GitLab.

In corporate network I have HTTPS URL, which looks like https://host/project/<project>/repo/<repo> and SSH URL looks like git@host/<project>/<repo>.git (where .git at the end is optional.

Is it possible to use the mechanism gitprovides to convert from one to another or I have to write a one-liner to wrap git-clone?

CodePudding user response:

From git help config:

url.<base>.insteadOf Any URL that starts with this value will be rewritten to start, instead, with <base>.

(emphasize mine - phd)

So insteadOf cannot parse URLs, extract substrings and put them in different order. Only the start of the URL can be rewritten.

CodePudding user response:

I use it for my corporate on-premise Git hosting service, provided, as phd suggest, I use the beginning of the URL.

The fact that the end of the URL might or might not include .git does not matter, as our Git repository hosting server will interpret both the same way.

From SSH to HTTPS:

git config --global url."https://host/".insteadOf git@host:
git config --global url."https://host/".insteadOf ssh://git@host/

From HTTPS to SSH:

git config --global url."ssh://git@host/".insteadOf https://host/
  • Related