简体   繁体   中英

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

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 git provides to convert from one to another or I have to write a one-liner to wrap git-clone?

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.

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM