Automatically Transforming Git URLs
Git is one of those tools that lots of people use, but few people truly master. I’m still on my own journey of Git mastery, and still have so very far to go. However, I did take one small step forward recently with the discovery of the ability for Git to automatically rewrite remote URLs. In this post, I’ll show you how to configure Git to automatically transform the URLs of Git remotes.
The key here is the url
configuration stanza and the associated insteadOf
keyword. Added to your Git configuration—either globally or on a per-repository basis—these configuration options will tell Git to use a different URL every time it encounters the specified original URL.
Here’s an example:
[url "[email protected]:org/"]
insteadOf = "https://github.com/org/"
The [email protected]:org/
is the replacement URL; that is, the URL that you want Git to use. The URL specified by the insteadOf
keyword is the original URL; that is, the URL you want Git to replace. As you can see in the example, it’s possible not only to transform HTTPS-based URLs to SSH URLs (or vice versa), but it’s possible to constrain this transformation to repositories belonging to a specific organization or Continue reading