When working on client or open source projects, I clone a lot of
Git repositories - either from GitHub, GitLab, Bitbucket
or Drupal.org. The standard git clone commands though provided by these sites
can be quite verbose with long repository URLs and use a mixture of different
protocols, and I’d regularly need to go back to each website and look up the
necessary command every time.
Any URL that starts with this value will be rewritten to start, instead, with
[base]. In cases where some site serves a large number of repositories, and
serves them with multiple access methods, and some users need to use different
access methods, this feature allows people to specify any of the equivalent
URLs and have Git automatically rewrite the URL to the best alternative for
the particular user, even for a never-before-seen repository on the site. When
more than one insteadOf strings match a given URL, the longest match is used.
Whilst examples are sparse,
it seems like
insteadOf is used for resolving protocol issues with repository URLs. However,
we can use it to simplify our clone commands, as mentioned above.
Example: cloning Drupal contrib projects
When working on Drupal core, or on a module, theme or distribution, you need to
have a cloned version of that repository to generate patch files from, and apply
patches to.
Again, here is the provided command to clone the Override Node Options module:
At the time of writing, the Git repository URL follow this same format -
https://git.drupal.org/project/{name}.git (also the .git file extension is
optional).
To shorten and simplify this, I can add this snippet to my ~/.gitconfig file:
I'm an Acquia-certified Drupal Triple Expert with 17
years of experience, an open-source software maintainer and Drupal core contributor, public speaker, live streamer, and host of the Beyond Blocks podcast.