How to add non-public repositories from command line with composer?
Asked Answered
B

1

65

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?

Bullet answered 31/7, 2015 at 9:46 Comment(0)
M
95

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).

Mooneyham answered 27/9, 2015 at 23:54 Comment(6)
and then add the package with composer require package-name:dev-branchname.Samala
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 :PWhimsey
Pro tip: you can use repositories.0 to avoid it from breaking its own json fileWageworker
To avoid overwrites when you want to add multiple repos, you can just replace repo-name with your own string.Phanotron
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 entryBandicoot
Here is a link to the documentation for this command: getcomposer.org/doc/03-cli.md#modifying-repositoriesReptant

© 2022 - 2024 — McMap. All rights reserved.