oliverdavies.uk/source/_posts/easier-git-repository-cloning-with-insteadof.md
2019-03-06 19:50:29 +00:00

1.4 KiB
Raw Blame History

title date tags draft
Easier Git Repository Cloning with inteadof 2019-02-06
true

What is insteadOf?

From the Git documentation:

{% raw %}

Any URL that starts with this value will be rewritten to start, instead, with . 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.

{% endraw %}

Example

For example to clone a Drupal module from Drupal.org, I can add this snippet to my ~/.gitconfig file:

[url "https://git.drupal.org/project/"]
    insteadOf = do:
    insteadOf = drupal:

This means that I can now do git clone drupal:<name> or git clone do:<name> to clone the repository, specifying the projects machine name.

For example, to clone the Override Node Options module, I can now do this using git clone drupal:override_node_options.

You can view my entire ~/.gitconfig file and my other dotfiles in my dotfiles repository on GitHub.