57

I want to add a new package which is not at packagist, it's a local or non-public repository. I know how to this in the composer.json. For example:

"repositories": [
    {
        "type": "vcs",
        "url": "https://bitbucket.org/xxxx/xxxxx.git"
    }
],
"require": {
    "xxxx/xxxxx": "dev-master"
},

But I want to do this from the command line so that I can add this non-public repositories in a provision file. Packages registered at Packagist I can add with:

composer require ....

But how to handle this with repositories not registered at Packagist?

George
  • 4,906
  • 2
  • 16
  • 21
brasileric
  • 1,017
  • 1
  • 8
  • 18

1 Answers1

89

You can run the following from the project root to add a repository to the project's composer.json:

composer config repositories.repo-name vcs https://github.com/<orgname or username>/repo

Then you can require the specific repo with:

composer require <orgname or username>/repo:dev-branchname

The Composer documentation covers it at Modifying Repositories (CLI: composer config).

hakre
  • 193,403
  • 52
  • 435
  • 836
Matt A
  • 1,096
  • 6
  • 6
  • 19
    and then add the package with `composer require package-name:dev-branchname`. – Patrick Feb 16 '16 at 19:41
  • 1
    this broke the json of my composer.json :D I wanted to run it command line to do it by the book and not hack composer.json but oh well .D that worked at least :P – OZZIE Dec 17 '18 at 12:43
  • 1
    Pro tip: you can use `repositories.0` to avoid it from breaking its own json file – ebsp Mar 25 '20 at 20:00
  • To avoid overwrites when you want to add multiple repos, you can just replace `repo-name` with your own string. – Michael Walter Nov 11 '20 at 12:02
  • 3
    `repositories.0` is not a valid solution, I just thought so as well, but it replaces the first entry and does not insert the new one before the first entry – Nickolaus Sep 21 '21 at 07:18
  • 1
    Here is a link to the documentation for this command: https://getcomposer.org/doc/03-cli.md#modifying-repositories – jofitz May 11 '22 at 15:16