How to require a fork with composer

Neilime picture Neilime · Nov 21, 2012 · Viewed 68.7k times · Source

here is my composer.json, i want to use Nodge's fork of lessphp project on Github

 "repositories": [{
    "type": "package",
    "package": {
        "version": "dev-master",
        "name": "nodge/lessphp",
        "source": {
            "url": "https://github.com/Nodge/lessphp.git",
            "type": "git",
            "reference": "master"
        },
        "autoload": {
            "classmap": ["lessc.inc.php"]
        }
    }
}],
"require": {
    "php": ">=5.3.3",
    "nodge/lessphp": "dev-master"
},

But i have this error when i make update :

nodge/lessphp dev-master -> no matching package found.

I don't know how to require it correctly this fork...

Any suggestions ?

Answer

Seldaek picture Seldaek · Nov 21, 2012

The most common (and easier) way of doing it is using a VCS repository.

All you have to do is add your fork as a repository and update the version constraint to point to your custom branch. Your custom branch name must be prefixed with dev-.

Example assuming you patched monolog to fix a bug in the bugfix branch:

{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/igorw/monolog"
        }
    ],
    "require": {
        "monolog/monolog": "dev-bugfix"
    }
}

Note that you don't change the require statement except to specify your bugfix branch. You still reference the upstream package (monolog/monolog), not your personal fork (igorw/monolog). You can read details in the docs