How to add a git repository to a composer.json file in Drupal 9

  1. Fork a Github module like https://github.com/protitude/module_markdown and change the composer.json like
@@ -1,5 +1,5 @@
{
-  "name": "protitude/markdown",
+  "name": "asanchez75/markdown",
  "description": "Allows content to be submitted using Markdown, a simple plain-text syntax that is transformed into valid HTML.",
  "type": "drupal-module",
  "homepage": "https://www.drupal.org/project/markdown",
  1. in the composer.json file of your Drupal 9 installation add the following lines
    "repositories": [
        {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        },
        {
            "type": "git",
            "url": "git@github.com:asanchez75/module_markdown.git",
            "reference": "8.x-1.x"
        }
    ],

  1. Run this command to retrieve the module from Github (dev plus the branch name)
composer require  asanchez75/markdown:dev-8.x-1.x

References

Tags