Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to require a fork with composer?

People also ask

How does a composer require work?

Composer - how it works? Composer uses Packagist.org as a main bundles' provider. It provides files from repositories that users report on the site. Packagist.org hands over such features as, among others: versioning or the integration with GitHub and/or bitbucket.

How do I update a single package in composer?

To update your packages json file is. Run composer update (on your local machine) to update the required packages and re-generate a composer. lock file. Commit the updated composer.

Is PHP required for composer?

And there really is no way to make Composer deal with this situation. The PHP version that is used when running composer update determines the resolution of dependencies, being influenced by PHP version and installed PHP extensions. You cannot define that a package should only be used for PHP versions between 5.3.


The most common (and easiest) 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


Using VCS works:

"name": "test/test",
"repositories": [{
    "type": "vcs",
    "url": "http://github.com/Nodge/lessphp"
}],
"require": {
    "leafo/lessphp": "dev-master"
},

But if I require a module that has this composer.json, it doesn't work. It installs the original project, not the fork.

Example

"name": "example/example",
"require": {
    "test/test": "dev-master"
},

I should mention again the repository. Is that normal?


If you can't get @Neilime answer to work for you, make sure your fork uses a different branch.

For example push your changes to a branch on your fork called my-bugfix, do not added dev- prefix in your branch name but in your composer.json you have to add it. Your composer file will look like:

"repositories":
[
    {
        "type": "vcs",
        "url": "http://github.com/yourname/packageName"
    }
],
"require": {
    "owner/packageName": "dev-my-bugfix"
},

I have tried many options but After I got this post I saw the light and it just worked perfect.

This is what you have to do:

1- Fork The repository

2- Create a branch and make the required modifications.

3- Add the repository label to your composer.json

"repositories": [
     
        {
            "type": "vcs",
            "url": "https://github.com/user/yourforkname"
        }
    ]

4- In the command line inside your project require your fork like this:

composer require vendor/packagename:dev-branchname

And Voilá!!

You have your fork version working